SlideShare a Scribd company logo
Code Optimization
• Optimization is the process of transforming a piece of code to make more efficient 
(either in terms of time or space) without changing its output or side-effects. The only 
difference visible to the code’s user should be that it runs faster and/or consumes less 
memory. It is really a misnomer that the name implies you are finding an "optimal" 
solution— in truth, optimization aims to improve, not perfect, the result. Optimization is 
the field where most compiler research is done today. The tasks of the front-end 
(scanning, parsing, semantic analysis) are well understood and unoptimized code 
generation is relatively straightforward. 
• Optimization, on the other hand, still retains a sizable measure of mysticism. High-quality 
optimization is more of an art than a science. Compilers for mature languages aren’t 
judged by how well they parse or analyze the code—you just expect it to do it right with 
a minimum of hassle—but instead by the quality of the object code they produce. Many 
optimization problems are NP-complete and thus most optimization algorithms rely on 
heuristics and approximations. It may be possible to come up with a case where a 
particular algorithm fails to produce better code or perhaps even makes it worse. 
• However, the algorithms tend to do rather well overall. It’s worth reiterating here that 
efficient code starts with intelligent decisions by the programmer. No one expects a 
compiler to replace BubbleSort with Quicksort. If a programmer uses a lousy algorithm, 
no amount of optimization can make it snappy. In terms of big-O, a compiler can only 
make improvements to constant factors. But, all else being equal, you want an algorithm 
with low constant factors.
When and Where To Optimize 
• There are a variety of tactics for attacking optimization. Some techniques 
are applied to the intermediate code, to streamline, rearrange, compress, 
etc. in an effort to reduce the size of the abstract syntax tree or shrink the 
number of TAC instructions. Others are applied as part of final code 
generation—choosing which instructions to emit, how to allocate registers 
and when/what to spill, and the like. And still other optimizations may 
occur after final code generation, attempting to re-work the assembly code 
itself into something more efficient. 
• Optimization can be very complex and time-consuming; it often involves 
multiple subphases, some of which are applied more than once. Most 
compilers allow optimization to be turned off to speed up compilation (gcc 
even has specific flags to turn on and off individual optimizations.)
Constant Folding 
• Constant folding refers to the evaluation at compile-time of 
expressions whose 
• operands are known to be constant. In its simplest form, it involves 
determining that all of the operands in an expression are constant-valued, 
performing the evaluation of the expression at compile-time, 
and then replacing the expression by its value. If an expression such 
as 10 + 2 * 3 is encountered, the compiler can compute the result at 
compile-time (16) and emit code as if the input contained the result 
rather than the original expression. Similarly, constant conditions, 
such as a conditional branch if a < b goto L1 else goto L2 where a and 
b are constant can be replaced by a Goto L1 or Goto L2 depending on 
the truth of the expression evaluated at compile-time.
Copy Propagation 
• This optimization is similar to constant propagation, but generalized 
to non-constant values. If we have an assignment a = b in our 
instruction stream, we can replace later occurrences of a with b 
(assuming there are no changes to either variable in-between). Given 
the way we generate TAC code, this is a particularly valuable 
optimization sinceit is able to eliminate a large number of instructions 
that only serve to copy values from one variable to another.
Common Subexpression Elimination 
• Two operations are common if they produce the same result. In such 
a case, it is likely more efficient to compute the result once and 
reference it the second time rather than re-evaluate it. An expression 
is alive if the operands used to compute the expression have not been 
changed. An expression that is no longer alive is dead.
PROGRAM FOR CONSTANT FOLDING 
• #include<stdio.h> 
• #include<conio.h> 
• int fib(int base) 
• {int result,tmp0,tmp1,tmp2,temp[12],f0,f1,i; 
• temp[0]=1; 
• temp[4]=0; 
• temp[1]=base < temp[0]; 
• temp[2]=base==temp[0]; 
• temp[3]=temp[1]||temp[2];
• if(temp[3]==temp[4]) 
• goto L0; 
• result=base; 
• goto L1; 
• L0: 
• temp[4]=0; 
• f0=temp[4]; 
• tmp0=f0; 
• temp[5]=1; 
• f1=temp[5]; 
• tmp1=f1; 
• printf("%d %d ",f0,f1);
• temp[6]=2; 
• i=temp[6]; 
• tmp2=i; 
• L2: 
• temp[7]=i<base; 
• temp[8]=i==base; 
• temp[9]=temp[7]||temp[8]; 
• if(temp[4]==temp[9]) 
• goto L3;
• temp[10]=tmp0+tmp1; 
• result=temp[10]; 
• printf("%d ",result); 
• tmp0=tmp1; 
• tmp1=result; 
• temp[11]=1; 
• temp[12]=tmp2+temp[11]; 
• tmp2=temp[12]; 
• goto L2; 
• L3: 
• L1: 
• return result; 
• } 
• void main() 
• { 
• int n; 
• clrscr(); 
• printf("nEnter a number:"); 
• scanf("%d",&n) ; 
• printf("nnfibonacci is %d",fib(n)); 
• getch(); 
• }
PROGRAM FOR COPY PROPOGATION 
• #include<stdio.h> 
• #include<conio.h> 
• int fib(int base) 
• { 
• int result,tmp0,tmp1,tmp2; 
• if (base <= 1) 
• { 
• result = base; 
• } 
• else 
• {
• int i; 
• int f0; 
• int f1; 
• f0 = 0; 
• tmp0=f0; 
• f1 = 1; 
• tmp1=f1; 
• i = 2; 
• tmp2=i; 
• printf("nn%dt%d",tmp0,tmp1); 
• while (tmp2 <= base) 
• { 
• result = tmp0 + tmp1; 
• printf("t%d",result); 
• tmp0 = tmp1; 
• tmp1 = result; 
• tmp2 = tmp2 + 1; 
• } 
• } 
• return result; 
• }
• void main() 
• { 
• int n; 
• clrscr(); 
• printf("nnEnter number:"); 
• scanf("%d",&n); 
• printf("nnFibonacci is: %dn",fib(n)); 
• getch(); 
• }
PROGRAM FOR COMMON SUBEXPRESSION 
ELIMINATION 
• #include<stdio.h> 
• #include<conio.h> 
• void main() 
• { 
• int a,b,c,d,e,f; 
• clrscr(); 
• printf("n Enter the values of a,b,c"); 
• scanf("n %d %d %d",&a,&b,&c); 
• d=a+b; 
• e=d*b;
• f=e+d+a; 
• printf("n D=%d",d); 
• printf("n E=%d",e); 
• printf("n F=%d",f); 
• getch(); 
• }
Ad

More Related Content

What's hot (20)

Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit Pandey
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
Karthik Vivek
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
Karthik Vivek
 
Peephole optimization techniques
Peephole optimization techniquesPeephole optimization techniques
Peephole optimization techniques
garishma bhatia
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
ZongYing Lyu
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
Janki Shah
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
Taymoor Nazmy
 
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
CAFxX
 
02 intel v_tune_session_02
02 intel v_tune_session_0202 intel v_tune_session_02
02 intel v_tune_session_02
Vivek Singh Chandel
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
Meghaj Mallick
 
Control Flow Analysis
Control Flow AnalysisControl Flow Analysis
Control Flow Analysis
Edgar Barbosa
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
liu_ming50
 
Arm developement
Arm developementArm developement
Arm developement
hirokiht
 
Compiler Optimization-Space Exploration
Compiler Optimization-Space ExplorationCompiler Optimization-Space Exploration
Compiler Optimization-Space Exploration
tmusabbir
 
Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)
DVClub
 
Parallel concepts1
Parallel concepts1Parallel concepts1
Parallel concepts1
Dr. C.V. Suresh Babu
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
Umair Younas
 
C- language Lecture 4
C- language Lecture 4C- language Lecture 4
C- language Lecture 4
Hatem Abd El-Salam
 
Recursion
RecursionRecursion
Recursion
Ashish Ranjan
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprograms
baran19901990
 
Optimization in Programming languages
Optimization in Programming languagesOptimization in Programming languages
Optimization in Programming languages
Ankit Pandey
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
Karthik Vivek
 
Peephole optimization techniques
Peephole optimization techniquesPeephole optimization techniques
Peephole optimization techniques
garishma bhatia
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
ZongYing Lyu
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
Janki Shah
 
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
CAFxX
 
Control Flow Analysis
Control Flow AnalysisControl Flow Analysis
Control Flow Analysis
Edgar Barbosa
 
Compiler optimization
Compiler optimizationCompiler optimization
Compiler optimization
liu_ming50
 
Arm developement
Arm developementArm developement
Arm developement
hirokiht
 
Compiler Optimization-Space Exploration
Compiler Optimization-Space ExplorationCompiler Optimization-Space Exploration
Compiler Optimization-Space Exploration
tmusabbir
 
Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)
DVClub
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
Umair Younas
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprograms
baran19901990
 

Viewers also liked (12)

States machine
States machineStates machine
States machine
Satyamevjayte Haxor
 
Keyword Presentation
Keyword PresentationKeyword Presentation
Keyword Presentation
Satyamevjayte Haxor
 
Types and roles
Types and rolesTypes and roles
Types and roles
Satyamevjayte Haxor
 
Uml Common Mechanism
Uml Common MechanismUml Common Mechanism
Uml Common Mechanism
Satyamevjayte Haxor
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
Satyamevjayte Haxor
 
Compilers
CompilersCompilers
Compilers
Satyamevjayte Haxor
 
What is symbol table?
What is symbol table?What is symbol table?
What is symbol table?
Satyamevjayte Haxor
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
Satyamevjayte Haxor
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
Emertxe Information Technologies Pvt Ltd
 
Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
Emertxe Information Technologies Pvt Ltd
 
Operating Systems: Processor Management
Operating Systems: Processor ManagementOperating Systems: Processor Management
Operating Systems: Processor Management
Damian T. Gordon
 
Two pass Assembler
Two pass AssemblerTwo pass Assembler
Two pass Assembler
Satyamevjayte Haxor
 
Ad

Similar to sCode optimization (20)

Introduction to code optimization by dipankar
Introduction to code optimization by dipankarIntroduction to code optimization by dipankar
Introduction to code optimization by dipankar
Dipankar Nalui
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
kapib57390
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
Ankur Goyal
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 Estimation
Lawrence Bernstein
 
Survelaine murillo ppt
Survelaine murillo pptSurvelaine murillo ppt
Survelaine murillo ppt
Survelaine Murillo
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Logic programming in python
Logic programming in pythonLogic programming in python
Logic programming in python
Pierre Carbonnelle
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)
Yogesh Deshpande
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
Self-Employed
 
Code optmize.pptx which is related to coding
Code optmize.pptx which is related to codingCode optmize.pptx which is related to coding
Code optmize.pptx which is related to coding
vamami6395
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
RahikAhmed1
 
Code Tuning
Code TuningCode Tuning
Code Tuning
guest4df97e3d
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
algorithms and data structure Time complexity
algorithms and data structure Time complexityalgorithms and data structure Time complexity
algorithms and data structure Time complexity
libannpost
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
Mark Veltzer
 
pm1
pm1pm1
pm1
Phil Mason
 
Python algorithm
Python algorithmPython algorithm
Python algorithm
Prof. Dr. K. Adisesha
 
Introduction to code optimization by dipankar
Introduction to code optimization by dipankarIntroduction to code optimization by dipankar
Introduction to code optimization by dipankar
Dipankar Nalui
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
NayanChandak1
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
kapib57390
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
Ankur Goyal
 
Improving Code Quality Through Effective Review Process
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
Dr. Syed Hassan Amin
 
Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 Estimation
Lawrence Bernstein
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)
Yogesh Deshpande
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
Self-Employed
 
Code optmize.pptx which is related to coding
Code optmize.pptx which is related to codingCode optmize.pptx which is related to coding
Code optmize.pptx which is related to coding
vamami6395
 
2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx2. Introduction to Algorithm.pptx
2. Introduction to Algorithm.pptx
RahikAhmed1
 
algorithms and data structure Time complexity
algorithms and data structure Time complexityalgorithms and data structure Time complexity
algorithms and data structure Time complexity
libannpost
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
Mark Veltzer
 
Ad

More from Satyamevjayte Haxor (9)

Patterns
PatternsPatterns
Patterns
Satyamevjayte Haxor
 
Uml class Diagram
Uml class DiagramUml class Diagram
Uml class Diagram
Satyamevjayte Haxor
 
Lexical
LexicalLexical
Lexical
Satyamevjayte Haxor
 
Linker
LinkerLinker
Linker
Satyamevjayte Haxor
 
Nested micro
Nested microNested micro
Nested micro
Satyamevjayte Haxor
 
Multiplier control unit
Multiplier control unitMultiplier control unit
Multiplier control unit
Satyamevjayte Haxor
 
Control unit design
Control unit designControl unit design
Control unit design
Satyamevjayte Haxor
 
Direct linking loaders
Direct linking loadersDirect linking loaders
Direct linking loaders
Satyamevjayte Haxor
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
Satyamevjayte Haxor
 

Recently uploaded (20)

Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb ClarkDeploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Peter Caitens
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-RuntimeReinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Natan Silnitsky
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
Surviving a Downturn Making Smarter Portfolio Decisions with OnePlan - Webina...
OnePlan Solutions
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb ClarkDeploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Peter Caitens
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Beyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraftBeyond the code. Complexity - 2025.05 - SwiftCraft
Beyond the code. Complexity - 2025.05 - SwiftCraft
Dmitrii Ivanov
 
GC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance EngineeringGC Tuning: A Masterpiece in Performance Engineering
GC Tuning: A Masterpiece in Performance Engineering
Tier1 app
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-RuntimeReinventing Microservices Efficiency and Innovation with Single-Runtime
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Natan Silnitsky
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptxThe-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
The-Future-is-Hybrid-Exploring-Azure’s-Role-in-Multi-Cloud-Strategies.pptx
james brownuae
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025Memory Management and Leaks in Postgres from pgext.day 2025
Memory Management and Leaks in Postgres from pgext.day 2025
Phil Eaton
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
Autodesk Inventor Crack (2025) Latest
Autodesk Inventor    Crack (2025) LatestAutodesk Inventor    Crack (2025) Latest
Autodesk Inventor Crack (2025) Latest
Google
 

sCode optimization

  • 2. • Optimization is the process of transforming a piece of code to make more efficient (either in terms of time or space) without changing its output or side-effects. The only difference visible to the code’s user should be that it runs faster and/or consumes less memory. It is really a misnomer that the name implies you are finding an "optimal" solution— in truth, optimization aims to improve, not perfect, the result. Optimization is the field where most compiler research is done today. The tasks of the front-end (scanning, parsing, semantic analysis) are well understood and unoptimized code generation is relatively straightforward. • Optimization, on the other hand, still retains a sizable measure of mysticism. High-quality optimization is more of an art than a science. Compilers for mature languages aren’t judged by how well they parse or analyze the code—you just expect it to do it right with a minimum of hassle—but instead by the quality of the object code they produce. Many optimization problems are NP-complete and thus most optimization algorithms rely on heuristics and approximations. It may be possible to come up with a case where a particular algorithm fails to produce better code or perhaps even makes it worse. • However, the algorithms tend to do rather well overall. It’s worth reiterating here that efficient code starts with intelligent decisions by the programmer. No one expects a compiler to replace BubbleSort with Quicksort. If a programmer uses a lousy algorithm, no amount of optimization can make it snappy. In terms of big-O, a compiler can only make improvements to constant factors. But, all else being equal, you want an algorithm with low constant factors.
  • 3. When and Where To Optimize • There are a variety of tactics for attacking optimization. Some techniques are applied to the intermediate code, to streamline, rearrange, compress, etc. in an effort to reduce the size of the abstract syntax tree or shrink the number of TAC instructions. Others are applied as part of final code generation—choosing which instructions to emit, how to allocate registers and when/what to spill, and the like. And still other optimizations may occur after final code generation, attempting to re-work the assembly code itself into something more efficient. • Optimization can be very complex and time-consuming; it often involves multiple subphases, some of which are applied more than once. Most compilers allow optimization to be turned off to speed up compilation (gcc even has specific flags to turn on and off individual optimizations.)
  • 4. Constant Folding • Constant folding refers to the evaluation at compile-time of expressions whose • operands are known to be constant. In its simplest form, it involves determining that all of the operands in an expression are constant-valued, performing the evaluation of the expression at compile-time, and then replacing the expression by its value. If an expression such as 10 + 2 * 3 is encountered, the compiler can compute the result at compile-time (16) and emit code as if the input contained the result rather than the original expression. Similarly, constant conditions, such as a conditional branch if a < b goto L1 else goto L2 where a and b are constant can be replaced by a Goto L1 or Goto L2 depending on the truth of the expression evaluated at compile-time.
  • 5. Copy Propagation • This optimization is similar to constant propagation, but generalized to non-constant values. If we have an assignment a = b in our instruction stream, we can replace later occurrences of a with b (assuming there are no changes to either variable in-between). Given the way we generate TAC code, this is a particularly valuable optimization sinceit is able to eliminate a large number of instructions that only serve to copy values from one variable to another.
  • 6. Common Subexpression Elimination • Two operations are common if they produce the same result. In such a case, it is likely more efficient to compute the result once and reference it the second time rather than re-evaluate it. An expression is alive if the operands used to compute the expression have not been changed. An expression that is no longer alive is dead.
  • 7. PROGRAM FOR CONSTANT FOLDING • #include<stdio.h> • #include<conio.h> • int fib(int base) • {int result,tmp0,tmp1,tmp2,temp[12],f0,f1,i; • temp[0]=1; • temp[4]=0; • temp[1]=base < temp[0]; • temp[2]=base==temp[0]; • temp[3]=temp[1]||temp[2];
  • 8. • if(temp[3]==temp[4]) • goto L0; • result=base; • goto L1; • L0: • temp[4]=0; • f0=temp[4]; • tmp0=f0; • temp[5]=1; • f1=temp[5]; • tmp1=f1; • printf("%d %d ",f0,f1);
  • 9. • temp[6]=2; • i=temp[6]; • tmp2=i; • L2: • temp[7]=i<base; • temp[8]=i==base; • temp[9]=temp[7]||temp[8]; • if(temp[4]==temp[9]) • goto L3;
  • 10. • temp[10]=tmp0+tmp1; • result=temp[10]; • printf("%d ",result); • tmp0=tmp1; • tmp1=result; • temp[11]=1; • temp[12]=tmp2+temp[11]; • tmp2=temp[12]; • goto L2; • L3: • L1: • return result; • } • void main() • { • int n; • clrscr(); • printf("nEnter a number:"); • scanf("%d",&n) ; • printf("nnfibonacci is %d",fib(n)); • getch(); • }
  • 11. PROGRAM FOR COPY PROPOGATION • #include<stdio.h> • #include<conio.h> • int fib(int base) • { • int result,tmp0,tmp1,tmp2; • if (base <= 1) • { • result = base; • } • else • {
  • 12. • int i; • int f0; • int f1; • f0 = 0; • tmp0=f0; • f1 = 1; • tmp1=f1; • i = 2; • tmp2=i; • printf("nn%dt%d",tmp0,tmp1); • while (tmp2 <= base) • { • result = tmp0 + tmp1; • printf("t%d",result); • tmp0 = tmp1; • tmp1 = result; • tmp2 = tmp2 + 1; • } • } • return result; • }
  • 13. • void main() • { • int n; • clrscr(); • printf("nnEnter number:"); • scanf("%d",&n); • printf("nnFibonacci is: %dn",fib(n)); • getch(); • }
  • 14. PROGRAM FOR COMMON SUBEXPRESSION ELIMINATION • #include<stdio.h> • #include<conio.h> • void main() • { • int a,b,c,d,e,f; • clrscr(); • printf("n Enter the values of a,b,c"); • scanf("n %d %d %d",&a,&b,&c); • d=a+b; • e=d*b;
  • 15. • f=e+d+a; • printf("n D=%d",d); • printf("n E=%d",e); • printf("n F=%d",f); • getch(); • }
  翻译: