SlideShare a Scribd company logo
COMPILER OPTIMIZATION
mr.C.KARTHIKEYAN
AP/ECE/RMKCET
WHAT IS A COMPILER?
In computing, a compiler is a computer
program that translates computer code written in
one programming language (the source language) into
another language (the target language).
Compilation
Compilation strategy :
compilation = translation + optimization
2 PHASES OF COMPILATION
Basic compilation phases
HLL
parsing, symbol table
machine-independent
optimizations
machine-dependent
optimizations
assembly
BLOCK DIAGRAM
BLOCK DIAGRAM
TERMS
STEP 1 Intro to lexical
analysis
Compiler optimization
PURPOSE OF LEXICAL
ANALYZER
LEXEMES
Compiler optimization
SPECIFICATONS OF TOKENS
CONVERSION
Compiler optimization
Compiler optimization
ROLE OF ERROR HANDLER
CORRECTED
STEP 2
STEP 2
STEP 3
STEP 4
STEP 4
STEP 5
STEP 5
STEP 6
Basic compilation
techniques
statement translation.
Procedure linkage.
Data structures.
Statement translation and
optimization
Source code is translated into
intermediate form such as CDFG.
CDFG is transformed/optimized.
CDFG is translated into instructions with
optimization decisions.
Instructions are further optimized.
Arithmetic expressions
a*b + 5*(c-d)
expression
DFG
* -
*
+
a b c d
5
2
3
4
1
Arithmetic expressions,
cont’d. a*b + 5*(c-d)
ADR r7,a
LDR r1,[r7]
ADR r7,b
LDR r2,[r7]
MUL r3,r1,r2
DFG
* -
*
+
a b c d
5
ADR r7,c
LDR r4,[r7]
ADR r7,d
LDR r5,[r7]
SUB r6,r4,r5
MOV r8, #5
MUL r9,r8,r6
ADD r10 r3,r9
code
Control code generation
if (a+b > 0)
x = 5;
else
x = 7;
a+b>0 x=5
x=7
false
True
3
21
Control code generation,
cont’d.
ADR r5,a
LDR r1,[r5]
ADR r5,b
LDR r2,b
ADD r3,r1,r2
BLE label3
a+b>0 x=5
x=7
LDR r3,#5
ADR r5,x
STR r3,[r5]
B statement
label 3 LDR r3,#7
ADR r5,x
STR r3,[r5]
statement
...
Procedure linkage
Need code to:
call and return;
pass parameters and results.
Parameters and returns are passed on
stack.
Procedures with few parameters may use
registers.
Procedure stacks
proc1
growth
proc1(int a) {
proc2(5);
}
proc2
SP
stack pointer
FP
frame pointer
5 accessed relative to SP
ARM procedure linkage
APCS (ARM Procedure Call Standard):
r0-r3 pass parameters into procedure. Extra
parameters are put on stack frame.
r0 holds return value.
r4-r7 hold register values.
r11 is frame pointer, r13 is stack pointer.
r10 holds limiting address on stack size to
check for stack overflows.
Data structures
Different types of data structures use
different data layouts.
Some address computation of data
structure can be done at compile time,
others must be computed at run time.
One-dimensional arrays
C array name points to 0th element:
a[0]
a[1]
a[2]
a
= *(a + 1)
Two-dimensional arrays
Column-major layout:
a[0,0]
a[0,1]
a[1,0]
a[1,1] = a[i*M+j]
...
M
...
N
PROGRAM OPTIMIZATION / COMPILER
OPTIMIZATION
Dead code elimination
Dead code:
#define DEBUG 0
if (DEBUG) dbg(p1);
Can be eliminated by
analysis of control
flow, constant
folding.
0
dbg(p1);
1
0
Loop transformations
Goals:
reduce loop overhead;
increase opportunities for pipelining;
improve memory system performance.
Loop unrolling
Reduces loop overhead, enables some
other optimizations.
for (i=0; i<100; i++)
add ();

for (i=0; i<50; i++) {
add ();
add ();
}
Loop fusion and
distribution
Fusion combines two loops into 1:
for (i=0; i<N; i++)
a[i] = b[i] * 5;
for (j=0; j<N; j++)
w[j] = c[j] * d[j];
 for (i=0; i<N; i++) {
a[i] = b[i] * 5;
w[i] = c[i] * d[i];
}
Loop tiling
Breaks one loop into a nest of loops.
Changes order of accesses within array.
Register allocation
Goals:
choose register to hold each variable;
determine lifespan of varible in the register.
Basic case: within basic block.
Register lifetime graph
w = a + b;
x = c + w;
y = c + d;
time
a
b
c
d
w
x
y
1 2 3
t=1
t=2
t=3
Instruction scheduling
Non-pipelined machines do not need
instruction scheduling: any order of
instructions that satisfies data
dependencies runs equally fast.
In pipelined machines, execution time of
one instruction depends on the nearby
instructions: opcode, operands.
Reservation table
A reservation table
relates
instructions/time to
CPU resources.
we check the
reservation table to
determine whether all
resources needed by
the instruction are
available at that time
Time/instr A B
instr1 X
instr2 X X
instr3 X
instr4 X
Software pipelining
pipeline bubbles appear that reduce
performance.
Software pipelining is a technique for
reordering instructions across several loop
iterations to reduce pipeline bubbles
Code Rescheduling to Avoid
Hazards
Fast code:
LW Rb,b
LW Rc,c
LW Re,e
ADD Ra,Rb,Rc
LW Rf,f
SW a,Ra
SUB Rd,Re,Rf
SW d,Rd
51
Try producing fast code for
a = b + c;
d = e – f;
assuming a, b, c, d ,e, and f in memory.
Slow code:
LW Rb,b
LW Rc,c
ADD Ra,Rb,Rc
SW a,Ra
LW Re,e
LW Rf,f
SUB Rd,Re,Rf
SW d,Rd
Compiler optimizes for performance. Hardware checks for safety.

More Related Content

PPTX
Chapter 03 arithmetic for computers
PDF
IIR filter realization using direct form I & II
PDF
105926921 cmos-digital-integrated-circuits-solution-manual-1
PPTX
Jump&Loop instruction
PDF
DFT Rules, set of rules with illustration
PPTX
Module 2 ARM CORTEX M3 Instruction Set and Programming
PPTX
Error control coding techniques
PPT
Microcontroller instruction set
Chapter 03 arithmetic for computers
IIR filter realization using direct form I & II
105926921 cmos-digital-integrated-circuits-solution-manual-1
Jump&Loop instruction
DFT Rules, set of rules with illustration
Module 2 ARM CORTEX M3 Instruction Set and Programming
Error control coding techniques
Microcontroller instruction set

What's hot (20)

PPTX
Srt division (2)
PDF
Flip flop
PPTX
Computer Organisation - Addressing Modes
PPT
Arm processor
PPTX
Embedded System Practical Workshop using the ARM Processor
PPTX
Digital communication methods
PPTX
DFT and its properties
PDF
Unit I.fundamental of Programmable DSP
PPTX
Data transfer and manipulation
PPTX
Algorithms DM
PDF
3510Chapter6Part2 (1).pdf
PPT
Impulse response and step response.ppt
PPTX
Clock divider by 3
ODP
Pc ie tl_layer (3)
DOC
Report on telnet
PPTX
Digital Registers & Counters
PDF
Logic synthesis using Verilog HDL
PPTX
Delta modulation
PPTX
Pipeline processing - Computer Architecture
PPT
Digital modulation techniques
Srt division (2)
Flip flop
Computer Organisation - Addressing Modes
Arm processor
Embedded System Practical Workshop using the ARM Processor
Digital communication methods
DFT and its properties
Unit I.fundamental of Programmable DSP
Data transfer and manipulation
Algorithms DM
3510Chapter6Part2 (1).pdf
Impulse response and step response.ppt
Clock divider by 3
Pc ie tl_layer (3)
Report on telnet
Digital Registers & Counters
Logic synthesis using Verilog HDL
Delta modulation
Pipeline processing - Computer Architecture
Digital modulation techniques
Ad

Similar to Compiler optimization (20)

PPTX
compiler design-Intermediate code generation.pptx
PPTX
Principal Sources of Optimization in compiler design
PPT
ERTS UNIT 3.ppt
PDF
SPCC_Sem6_Chapter 6_Code Optimization part
PDF
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
PDF
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
PPTX
Unit 3.1 Algorithm and Flowchart
PPTX
Compiler optimization techniques
PDF
Code optimization in compiler design
PPT
Code Optimization Lec#7.ppt Code Optimizer
PPTX
Download RarmaRadio Pro Crack Latest [2025]
PPTX
Code_Optimization_Compiler_Design software .pptx
PPTX
NCH VideoPad Pro Cracked Version Download
PPTX
Download Artweaver Plus Cracked Version Free
PPTX
PowerDirector Activated Full Tested Download
PPTX
Downlaod Wise Registry Cleaner Pro Crack
PPTX
Autodesk CFD Ultimate Crack Latest Version
PPTX
Latest TreeSize Professional 9 Crack Download
PPT
basics of optimizations presentation s
DOC
Compilerdesignnew 091219090526-phpapp02
compiler design-Intermediate code generation.pptx
Principal Sources of Optimization in compiler design
ERTS UNIT 3.ppt
SPCC_Sem6_Chapter 6_Code Optimization part
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
Unit 3.1 Algorithm and Flowchart
Compiler optimization techniques
Code optimization in compiler design
Code Optimization Lec#7.ppt Code Optimizer
Download RarmaRadio Pro Crack Latest [2025]
Code_Optimization_Compiler_Design software .pptx
NCH VideoPad Pro Cracked Version Download
Download Artweaver Plus Cracked Version Free
PowerDirector Activated Full Tested Download
Downlaod Wise Registry Cleaner Pro Crack
Autodesk CFD Ultimate Crack Latest Version
Latest TreeSize Professional 9 Crack Download
basics of optimizations presentation s
Compilerdesignnew 091219090526-phpapp02
Ad

More from Karthik Vivek (20)

PPTX
Peak detector, instrumentation amp
PPTX
U3 op amp applications
PPTX
Unit 1 ic fab
PPTX
Fabrication of diodes, resistors, capacitors, fe ts
PPT
Unit 3 part2
PPT
Unit 3 part2
PPT
Unit 3 part2
PPTX
Embedded programming u3 part 1
PPTX
ARM stacks, subroutines, Cortex M3, LPC 214X
PPTX
ARM inst set part 2
PPTX
ARM instruction set
PPTX
ARM instruction set
PPTX
ARM Versions, architecture
PPTX
Unit 1a train
PPTX
Unit2 arm
PPTX
Unit 1c
PPTX
Unit 1b
PPTX
Unit 1a train
PPTX
Introduction
PPTX
unit 2- OP AMP APPLICATIONS
Peak detector, instrumentation amp
U3 op amp applications
Unit 1 ic fab
Fabrication of diodes, resistors, capacitors, fe ts
Unit 3 part2
Unit 3 part2
Unit 3 part2
Embedded programming u3 part 1
ARM stacks, subroutines, Cortex M3, LPC 214X
ARM inst set part 2
ARM instruction set
ARM instruction set
ARM Versions, architecture
Unit 1a train
Unit2 arm
Unit 1c
Unit 1b
Unit 1a train
Introduction
unit 2- OP AMP APPLICATIONS

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
master seminar digital applications in india
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
TR - Agricultural Crops Production NC III.pdf
master seminar digital applications in india
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharma ospi slides which help in ospi learning
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Types and Its function , kingdom of life
Final Presentation General Medicine 03-08-2024.pptx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

Compiler optimization