SlideShare a Scribd company logo
Presented by
INDUMATHI.A (BP150517)
 The advantage of generating code for a basic block
from its dag representation is that, from a dag we can
easily see how to rearrange the order of the final
computation sequence than we can starting from a
linear sequence of three-address statements or
quadruples
 t1 := a + b
 t2 := c + d
 t3 := e - t2
 t4 := t1 - t3
(1) MOV a, R0
(2) ADD b, R0
(3) MOV c, R1
(4) ADD d, R1
(5) MOV R0, t1
(6) MOV e, R0
(7) SUB R1, R0
(8) MOV t1, R1
(9) SUB R0, R1
(10) MOV R1, t4
-
+ -
+a0 b0 e0
c0 d0
t1
t2
t3
t4
 t2 := c + d
 t3 := e - t2
 t1 := a + b
 t4 := t1 - t3
(1) MOV c, R0
(2) ADD d, R0
(3) MOV e, R1
(4) SUB R0, R1
(5) MOV a, R0
(6) ADD b, R0
(7) SUB R1, R0
(8) MOV R0, t4
-
+ -
+a0 b0 e0
c0 d0
t1
t2
t3
t4
The heuristic ordering algorithm attempts to make
the evaluation of a node immediately follow the
evaluation of its leftmost argument.
 while unlisted interior nodes remain do begin
 select an unlisted node n, all of whose
 parents have been listed;
 list n;
 while the leftmost child m of n has no
unlisted
 parents and is not a leaf do begin
 list m;
 n := m;
 end
 end
32
1
-
+
*
a0 b0
c0
+
d0 e0
6
-+
*
4
5 7
t7 := d + e
t6 := a + b
t5 := t6 - c
t4 := t5 * t7
t3 := t4 - e
t2 := t6 + t4
t1 := t2 * t3
 Label each node of the tree bottom-up with an
integer denoting fewest number of registers
required to evaluate the tree with no stores of
immediate results
 Generate code during a tree traversal by first
evaluating the operand requiring more registers
 if n is a leaf then
 if n is the leftmost child of its parent then
 label(n) := 1
 else
 label(n) := 0
 else begin
 let n1, n2, …, nk be the children of n ordered
by label so that label(n1)  label(n2)  … 
label(nk);
label(n) := max1 i  k(label(ni) + i - 1)
 end
label(n) = max(l1, l2), if l1  l2
l1 + 1, if l1 = l2
t1
t4
t2a b
c
t3
d
e
1
2
1 2
0
1 0
11
For binary interior nodes:
 Use a stack rstack to allocate registers R0,
R1, …, R(r-1)
 The value of a tree is always computed in
the top register on rstack
 The function swap(rstack) interchanges the
top two registers on rstack
 Use a stack tstack to allocate temporary
memory locations T0, T1, ...
op
n1 n2
op
n1 n2
op
n1 n2
label(n1) < label(n2) label(n2)  label(n1) both labels  r
op
n1 n2n name
name
/* case 1 */
begin
let name be the operand represented by n2;
gencode(n1);
print op || name || ',' || top(rstack)
end
/* case 2 */
begin
swap(rstack); gencode(n2);
R := pop(rstack); gencode(n1);
print op || R || ',' || top(rstack);
push(rstack, R); swap(rstack);
end
/* case 3 */
begin
gencode(n1);
R := pop(rstack); gencode(n2);
print op || R || ',' || top(rstack);
push(rstack, R);
end
/* case 4 */
begin
gencode(n2); T := pop(tstack);
print 'MOV' || top(rstack) || ',' || T;
gencode(n1); push(tstack, T);
print op || T || ',' || top(rstack);
end
gencode(t4) [R1, R0] /* 2 */
gencode(t3) [R0, R1] /* 3 */
gencode(e) [R0, R1] /* 0 */
print MOV e, R1
gencode(t2) [R0] /* 1 */
gencode(c) [R0] /* 0 */
print MOV c, R0
print ADD d, R0
print SUB R0, R1
gencode(t1) [R0] /* 1 */
gencode(a) [R0] /* 0 */
print MOV a, R0
print ADD b, R0
print SUB R1, R0
t1
t4
t2a b
c
t3
d
e
1
2
1 2
0
1 0
11
 Some operations like multiplication, division,
or a function call normally require more than
one register
 The labeling algorithm needs to ensure that
label(n) is always at least the number of
registers required by the operation
label(n) = max(2, l1, l2), if l1  l2
l1 + 1, if l1 = l2
+
T1
+
T1
1 l
max(2, l)
l 0
l
+
T1
T4
+
T2 T3
+
Ti3
+
Ti1 Ti2
+
Ti4
+
associative
commutative
largest
commutative
 Nodes with more than one parent in a dag
are called shared nodes
 Optimal code generation for dags on both a
one-register machine or an unlimited number
of registers machine are NP-complete

More Related Content

What's hot

Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
Akhil Kaushik
 
Design issues for the layers
Design issues for the layersDesign issues for the layers
Design issues for the layersjayaprakash
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
Kalaimathi Vijayakumar
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
Radhakrishnan Chinnusamy
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
R Islam
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
Mani Kanth
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
Bharat Rathore
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
A. S. M. Shafi
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
Kuppusamy P
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Multi dimensional turing machine
Multi dimensional turing machineMulti dimensional turing machine
Multi dimensional turing machine
NiteshSingh405
 
Issues in knowledge representation
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representationSravanthi Emani
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
Hitesh Mohapatra
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
Acad
 
Network layer - design Issues
Network layer - design IssuesNetwork layer - design Issues
Network layer - design Issues
قصي نسور
 

What's hot (20)

Code generation
Code generationCode generation
Code generation
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Design issues for the layers
Design issues for the layersDesign issues for the layers
Design issues for the layers
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Multi dimensional turing machine
Multi dimensional turing machineMulti dimensional turing machine
Multi dimensional turing machine
 
Issues in knowledge representation
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representation
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
 
Network layer - design Issues
Network layer - design IssuesNetwork layer - design Issues
Network layer - design Issues
 

Viewers also liked

La frase III
La frase IIILa frase III
La frase III
Sheryl Rojas
 
MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...
MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...
MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...
IAEME Publication
 
Guru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017M
Guru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017MGuru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017M
Guru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017M
Waalid Aisya
 
04 norma manejo y tratamiento de its - 2008
04   norma  manejo y tratamiento de its - 200804   norma  manejo y tratamiento de its - 2008
04 norma manejo y tratamiento de its - 2008
Carmen Salazar
 
COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK
COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK
COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK
IAEME Publication
 
marorapa
marorapamarorapa
Ejercicios Gantt Pertcmp
Ejercicios Gantt PertcmpEjercicios Gantt Pertcmp
Ejercicios Gantt Pertcmp
Jonas Oraa
 
MANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKE
MANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKEMANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKE
MANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKE
IAEME Publication
 
Ruta de implementación del modelo educativo
Ruta de implementación del modelo educativoRuta de implementación del modelo educativo
Ruta de implementación del modelo educativo
Lucy Galán
 
Сервис StatKino_Хакатон
Сервис StatKino_ХакатонСервис StatKino_Хакатон
Сервис StatKino_Хакатон
Ksu Vinogradova
 
Glass material is used as fine aggregates
Glass material is used as fine aggregatesGlass material is used as fine aggregates
Glass material is used as fine aggregates
jerry vasoya
 
NUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSOR
NUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSORNUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSOR
NUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSOR
IAEME Publication
 
MSB kureha Cots and Apron
MSB  kureha Cots and ApronMSB  kureha Cots and Apron
MSB kureha Cots and Apron
SKT TEXTILE SERVICE INDIA PVT LTD
 
Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...
Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...
Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...
AGM Abogados
 
Brochure AGM Abogados 2016 English – Legal services
Brochure AGM Abogados 2016 English – Legal servicesBrochure AGM Abogados 2016 English – Legal services
Brochure AGM Abogados 2016 English – Legal services
AGM Abogados
 
ÉTS - Cours GES840 - Atelier de recherche de brevets
ÉTS - Cours GES840 - Atelier de recherche de brevetsÉTS - Cours GES840 - Atelier de recherche de brevets
ÉTS - Cours GES840 - Atelier de recherche de brevets
Promotion du développement des compétences informationnelles (PDCI)
 
ÉTS - Cours MEC200 - Atelier de recherche documentaire
ÉTS - Cours MEC200 - Atelier de recherche documentaireÉTS - Cours MEC200 - Atelier de recherche documentaire
ÉTS - Cours MEC200 - Atelier de recherche documentaire
Promotion du développement des compétences informationnelles (PDCI)
 
робота з графічними об
робота з графічними обробота з графічними об
робота з графічними об
marunasorokina
 
La computadora
La computadoraLa computadora
La computadora
felipe cordoba peña
 
Medicolegal aspects in obstetrics
Medicolegal aspects in obstetricsMedicolegal aspects in obstetrics
Medicolegal aspects in obstetrics
Aziza Negm
 

Viewers also liked (20)

La frase III
La frase IIILa frase III
La frase III
 
MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...
MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...
MULTIPHASE SIMULATION OF AUTOMOTIVE HVAC EVAPORATOR USING R134A AND R1234YF R...
 
Guru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017M
Guru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017MGuru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017M
Guru Panitia Pendidikan Islam SK Taman Selasih 1438H/2017M
 
04 norma manejo y tratamiento de its - 2008
04   norma  manejo y tratamiento de its - 200804   norma  manejo y tratamiento de its - 2008
04 norma manejo y tratamiento de its - 2008
 
COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK
COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK
COMPUTATIONAL ANALYSIS OF STEPPED AND STRAIGHT MICROCHANNEL HEAT SINK
 
marorapa
marorapamarorapa
marorapa
 
Ejercicios Gantt Pertcmp
Ejercicios Gantt PertcmpEjercicios Gantt Pertcmp
Ejercicios Gantt Pertcmp
 
MANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKE
MANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKEMANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKE
MANUFACTURING AND FORCE DETERMINATION OF COMPOSITE DISC BRAKE
 
Ruta de implementación del modelo educativo
Ruta de implementación del modelo educativoRuta de implementación del modelo educativo
Ruta de implementación del modelo educativo
 
Сервис StatKino_Хакатон
Сервис StatKino_ХакатонСервис StatKino_Хакатон
Сервис StatKino_Хакатон
 
Glass material is used as fine aggregates
Glass material is used as fine aggregatesGlass material is used as fine aggregates
Glass material is used as fine aggregates
 
NUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSOR
NUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSORNUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSOR
NUMERICAL SOLUTIONS FOR PERFORMANCE PREDICTION OF CENTRIFUGAL COMPRESSOR
 
MSB kureha Cots and Apron
MSB  kureha Cots and ApronMSB  kureha Cots and Apron
MSB kureha Cots and Apron
 
Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...
Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...
Jornada Movilidad internacional de trabajadores (AGM Abogados & Wills Towers ...
 
Brochure AGM Abogados 2016 English – Legal services
Brochure AGM Abogados 2016 English – Legal servicesBrochure AGM Abogados 2016 English – Legal services
Brochure AGM Abogados 2016 English – Legal services
 
ÉTS - Cours GES840 - Atelier de recherche de brevets
ÉTS - Cours GES840 - Atelier de recherche de brevetsÉTS - Cours GES840 - Atelier de recherche de brevets
ÉTS - Cours GES840 - Atelier de recherche de brevets
 
ÉTS - Cours MEC200 - Atelier de recherche documentaire
ÉTS - Cours MEC200 - Atelier de recherche documentaireÉTS - Cours MEC200 - Atelier de recherche documentaire
ÉTS - Cours MEC200 - Atelier de recherche documentaire
 
робота з графічними об
робота з графічними обробота з графічними об
робота з графічними об
 
La computadora
La computadoraLa computadora
La computadora
 
Medicolegal aspects in obstetrics
Medicolegal aspects in obstetricsMedicolegal aspects in obstetrics
Medicolegal aspects in obstetrics
 

Similar to Generating code from dags

Mergesort
MergesortMergesort
Mergesort
luzenith_g
 
Compiler Design Unit 3
Compiler Design Unit 3Compiler Design Unit 3
Compiler Design Unit 3
Jena Catherine Bel D
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
Pradeep Bisht
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
MDSayem35
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
bryan111472
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
venkatapranaykumarGa
 
time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdf
SrinivasaReddyPolamR
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
Vipul Naik
 
Polyphase
PolyphasePolyphase
LR parsing
LR parsingLR parsing
LR parsing
ichikaz3
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdf
SHUJEHASSAN
 
Graph for Coulomb damped oscillation
Graph for Coulomb damped oscillationGraph for Coulomb damped oscillation
Graph for Coulomb damped oscillation
phanhung20
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manual
to2001
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
SajalFayyaz
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
Tele4653 l5
Tele4653 l5Tele4653 l5
Tele4653 l5Vin Voro
 
高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価
高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価
高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価
Kota Abe
 

Similar to Generating code from dags (20)

Ch8a
Ch8aCh8a
Ch8a
 
Mergesort
MergesortMergesort
Mergesort
 
Compiler Design Unit 3
Compiler Design Unit 3Compiler Design Unit 3
Compiler Design Unit 3
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
 
CS330-Lectures Statistics And Probability
CS330-Lectures Statistics And ProbabilityCS330-Lectures Statistics And Probability
CS330-Lectures Statistics And Probability
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
 
time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdf
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Polyphase
PolyphasePolyphase
Polyphase
 
Ch5b
Ch5bCh5b
Ch5b
 
LR parsing
LR parsingLR parsing
LR parsing
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdf
 
Graph for Coulomb damped oscillation
Graph for Coulomb damped oscillationGraph for Coulomb damped oscillation
Graph for Coulomb damped oscillation
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manual
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Tele4653 l5
Tele4653 l5Tele4653 l5
Tele4653 l5
 
Ch8b
Ch8bCh8b
Ch8b
 
高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価
高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価
高いChurn耐性と検索性能を持つキー順序保存型構造化オーバレイネットワークSuzakuの提案と評価
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

Generating code from dags

  • 2.  The advantage of generating code for a basic block from its dag representation is that, from a dag we can easily see how to rearrange the order of the final computation sequence than we can starting from a linear sequence of three-address statements or quadruples
  • 3.  t1 := a + b  t2 := c + d  t3 := e - t2  t4 := t1 - t3 (1) MOV a, R0 (2) ADD b, R0 (3) MOV c, R1 (4) ADD d, R1 (5) MOV R0, t1 (6) MOV e, R0 (7) SUB R1, R0 (8) MOV t1, R1 (9) SUB R0, R1 (10) MOV R1, t4 - + - +a0 b0 e0 c0 d0 t1 t2 t3 t4
  • 4.  t2 := c + d  t3 := e - t2  t1 := a + b  t4 := t1 - t3 (1) MOV c, R0 (2) ADD d, R0 (3) MOV e, R1 (4) SUB R0, R1 (5) MOV a, R0 (6) ADD b, R0 (7) SUB R1, R0 (8) MOV R0, t4 - + - +a0 b0 e0 c0 d0 t1 t2 t3 t4
  • 5. The heuristic ordering algorithm attempts to make the evaluation of a node immediately follow the evaluation of its leftmost argument.
  • 6.  while unlisted interior nodes remain do begin  select an unlisted node n, all of whose  parents have been listed;  list n;  while the leftmost child m of n has no unlisted  parents and is not a leaf do begin  list m;  n := m;  end  end
  • 7. 32 1 - + * a0 b0 c0 + d0 e0 6 -+ * 4 5 7 t7 := d + e t6 := a + b t5 := t6 - c t4 := t5 * t7 t3 := t4 - e t2 := t6 + t4 t1 := t2 * t3
  • 8.  Label each node of the tree bottom-up with an integer denoting fewest number of registers required to evaluate the tree with no stores of immediate results  Generate code during a tree traversal by first evaluating the operand requiring more registers
  • 9.  if n is a leaf then  if n is the leftmost child of its parent then  label(n) := 1  else  label(n) := 0  else begin  let n1, n2, …, nk be the children of n ordered by label so that label(n1)  label(n2)  …  label(nk); label(n) := max1 i  k(label(ni) + i - 1)  end
  • 10. label(n) = max(l1, l2), if l1  l2 l1 + 1, if l1 = l2 t1 t4 t2a b c t3 d e 1 2 1 2 0 1 0 11 For binary interior nodes:
  • 11.  Use a stack rstack to allocate registers R0, R1, …, R(r-1)  The value of a tree is always computed in the top register on rstack  The function swap(rstack) interchanges the top two registers on rstack  Use a stack tstack to allocate temporary memory locations T0, T1, ...
  • 12. op n1 n2 op n1 n2 op n1 n2 label(n1) < label(n2) label(n2)  label(n1) both labels  r op n1 n2n name name
  • 13. /* case 1 */ begin let name be the operand represented by n2; gencode(n1); print op || name || ',' || top(rstack) end /* case 2 */ begin swap(rstack); gencode(n2); R := pop(rstack); gencode(n1); print op || R || ',' || top(rstack); push(rstack, R); swap(rstack); end
  • 14. /* case 3 */ begin gencode(n1); R := pop(rstack); gencode(n2); print op || R || ',' || top(rstack); push(rstack, R); end /* case 4 */ begin gencode(n2); T := pop(tstack); print 'MOV' || top(rstack) || ',' || T; gencode(n1); push(tstack, T); print op || T || ',' || top(rstack); end
  • 15. gencode(t4) [R1, R0] /* 2 */ gencode(t3) [R0, R1] /* 3 */ gencode(e) [R0, R1] /* 0 */ print MOV e, R1 gencode(t2) [R0] /* 1 */ gencode(c) [R0] /* 0 */ print MOV c, R0 print ADD d, R0 print SUB R0, R1 gencode(t1) [R0] /* 1 */ gencode(a) [R0] /* 0 */ print MOV a, R0 print ADD b, R0 print SUB R1, R0 t1 t4 t2a b c t3 d e 1 2 1 2 0 1 0 11
  • 16.  Some operations like multiplication, division, or a function call normally require more than one register  The labeling algorithm needs to ensure that label(n) is always at least the number of registers required by the operation label(n) = max(2, l1, l2), if l1  l2 l1 + 1, if l1 = l2
  • 17. + T1 + T1 1 l max(2, l) l 0 l + T1 T4 + T2 T3 + Ti3 + Ti1 Ti2 + Ti4 + associative commutative largest commutative
  • 18.  Nodes with more than one parent in a dag are called shared nodes  Optimal code generation for dags on both a one-register machine or an unlimited number of registers machine are NP-complete