SlideShare a Scribd company logo
1 of 18
university of wah,wah cantt PAKISTAN. 1
GROUP MEMBERS
ANAS SATTI
ZEESHAN AKRAM
TOQEER QAYYUM
university of wah,wah cantt PAKISTAN.
History
 In computer science, the Sethi–Ullman algorithm is
an algorithm named after Ravi Sethi and Jeffrey D. Ullman ,
its inventors, for translating abstract syntax trees into machine
code that uses as few instructions as possible.
university of wah,wah cantt PAKISTAN.
Cont..
 Ravi Sethi (born 1947) is an Indian computer scientist retired
from Bell Labs and president of Avaya Labs Research.
 Jeffrey David "Jeff" Ullman (born November 22, 1942) is
a computer scientist and professor at Stanford University
university of wah,wah cantt PAKISTAN.
Overview
 When generating code for arithmetic expressions,
the compiler has to decide which is the best way to translate
the expression in terms of number of instructions used as well
as number of registers needed to evaluate a certain subtree
university of wah,wah cantt PAKISTAN.
Cont...
 The Sethi–Ullman algorithm fulfils the property of producing
code which needs the least number of instructions possible as
well as the least number of storage reference
university of wah,wah cantt PAKISTAN.
Optimal Code Generation
 Generates the shortest sequence of instructions
 Provably optimal algorithm (w.r.t. length of the
sequence)
 Suitable for expression trees
 All computations are carried out in registers
 Always computes the left subtree into a register and
reuses it immediately
university of wah,wah cantt PAKISTAN.
Working
 Traverse the abstract syntax tree in pre- or postorder
 For every non-constant leaf node, assign a 1.
 For every constant leaf node assign a 0.
 For every non-leaf node n, assign the number of
registers needed to evaluate the respective subtrees
of n.
university of wah,wah cantt PAKISTAN.
• If the number of registers needed in the left subtree (l) are not
equal to the number of registers needed in the right subtree
(r), the number of registers needed for the current node n is
max(l, r). If l == r, then the number of registers needed for the
current node is l + 1.
university of wah,wah cantt PAKISTAN.
Code emission
 If the number of registers needed to compute the left
subtree of node n is bigger than the number of registers
for the right subtree, then the left subtree is evaluated
first
university of wah,wah cantt PAKISTAN.
Cont...
 If the right subtree needs more registers than the left
subtree, the right subtree is evaluated first accordingly.
If both sub trees need equal as much registers, then the
order of evaluation is irrelevant.
university of wah,wah cantt PAKISTAN.
Example
AST traverse ( b +c +f *g)*(d+3),,,
*
/ 
/ 
+ +
/  / 
/  d 3
+ *
/  / 
b c f g
university of wah,wah cantt PAKISTAN.
Cont...
 Now we start traversing the tree (in preorder for now),
assigning the number of registers needed to evaluate
each subtree (note that the last summand in the
expression is a constant)
university of wah,wah cantt PAKISTAN.
Cont...
*2
/ 
/ 
+2 +1
/  / 
/  d1 30
+1 *1
/  / 
b1 c0 f1 g0
university of wah,wah cantt PAKISTAN.
Implementation
 From this tree it can be seen that we need 2 registers to
compute the left subtree of the '*', but only 1 register to
compute the right subtree. Nodes 'c' and 'g' do not need
registers for the following reasons:
 If T is a tree leaf, then the number of registers to
evaluate T is either 1 or 0 depending whether T is a left
or a right subtree
university of wah,wah cantt PAKISTAN.
Cont...
 Therefore we shall start to emit code for the left
subtree first, because we might run into the situation
that we only have 2 registers left to compute the whole
expression
 If we now computed the right subtree first (which
needs only 1 register), we would then need a register to
hold the result of the right subtree while computing the
left subtree (which would still need 2 registers),
therefore needing 3 registers concurrently
university of wah,wah cantt PAKISTAN.
Cont...
 Computing the left subtree first needs 2 registers, but
the result can be stored in 1, and since the right
subtree needs only 1 register to compute, the
evaluation of the expression can do with only 2 registers
left.
university of wah,wah cantt PAKISTAN.
Uses
 Minimizes register use
 Minimizes execution time
university of wah,wah cantt PAKISTAN.

More Related Content

What's hot

Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsHoang Nguyen
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductionsirshad17
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1SSE_AndyLi
 
State space modeling_introduction
State space modeling_introductionState space modeling_introduction
State space modeling_introductionDeva Karan
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannualmaamir farooq
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfadeepinderbedi
 

What's hot (9)

Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
State space analysis
State space analysisState space analysis
State space analysis
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 
State space modeling_introduction
State space modeling_introductionState space modeling_introduction
State space modeling_introduction
 
Selection sort lab mannual
Selection sort lab mannualSelection sort lab mannual
Selection sort lab mannual
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
 
Automata
AutomataAutomata
Automata
 

Viewers also liked

Guy.Kfir - Cost Optimization at Scale - NL Summit 2016
Guy.Kfir - Cost Optimization at Scale - NL Summit 2016Guy.Kfir - Cost Optimization at Scale - NL Summit 2016
Guy.Kfir - Cost Optimization at Scale - NL Summit 2016Guy KFIR
 
ManageYourCostsAndGovernYourUsageOnAWS[1]
ManageYourCostsAndGovernYourUsageOnAWS[1]ManageYourCostsAndGovernYourUsageOnAWS[1]
ManageYourCostsAndGovernYourUsageOnAWS[1]Guy KFIR
 
Language translation system p
Language translation system pLanguage translation system p
Language translation system panassatti5
 
Innstikk i Sunnhordland
Innstikk i SunnhordlandInnstikk i Sunnhordland
Innstikk i SunnhordlandSunnhordland
 
Bli digital brukar
Bli digital brukarBli digital brukar
Bli digital brukarSunnhordland
 
Question 1 part b
Question 1 part bQuestion 1 part b
Question 1 part bthahmina
 
Grafika c-sharp
Grafika c-sharpGrafika c-sharp
Grafika c-sharpvojael
 
Annonseplasseringar papir
Annonseplasseringar papirAnnonseplasseringar papir
Annonseplasseringar papirSunnhordland
 

Viewers also liked (16)

Kjøp abonnement
Kjøp abonnementKjøp abonnement
Kjøp abonnement
 
Guy.Kfir - Cost Optimization at Scale - NL Summit 2016
Guy.Kfir - Cost Optimization at Scale - NL Summit 2016Guy.Kfir - Cost Optimization at Scale - NL Summit 2016
Guy.Kfir - Cost Optimization at Scale - NL Summit 2016
 
ManageYourCostsAndGovernYourUsageOnAWS[1]
ManageYourCostsAndGovernYourUsageOnAWS[1]ManageYourCostsAndGovernYourUsageOnAWS[1]
ManageYourCostsAndGovernYourUsageOnAWS[1]
 
Language translation system p
Language translation system pLanguage translation system p
Language translation system p
 
Innstikk i Sunnhordland
Innstikk i SunnhordlandInnstikk i Sunnhordland
Innstikk i Sunnhordland
 
Bli digital brukar
Bli digital brukarBli digital brukar
Bli digital brukar
 
Annonser papir
Annonser papirAnnonser papir
Annonser papir
 
Mobilannonser
MobilannonserMobilannonser
Mobilannonser
 
Question 1 part b
Question 1 part bQuestion 1 part b
Question 1 part b
 
Unit 2
Unit 2Unit 2
Unit 2
 
Bonami
BonamiBonami
Bonami
 
Annonser nett
Annonser nettAnnonser nett
Annonser nett
 
Årebladet 1 2013
Årebladet 1 2013Årebladet 1 2013
Årebladet 1 2013
 
Free Zone Nouadhibou Mauritania
Free Zone Nouadhibou MauritaniaFree Zone Nouadhibou Mauritania
Free Zone Nouadhibou Mauritania
 
Grafika c-sharp
Grafika c-sharpGrafika c-sharp
Grafika c-sharp
 
Annonseplasseringar papir
Annonseplasseringar papirAnnonseplasseringar papir
Annonseplasseringar papir
 

Similar to Sethi ullman persent

COMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptCOMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptssuserebb9821
 
COMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxCOMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxssuserebb9821
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdfMemeMiner
 
Stacks and Queues with Linked List.pdf
Stacks and Queues with Linked List.pdfStacks and Queues with Linked List.pdf
Stacks and Queues with Linked List.pdfGKalyani4
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in CJabs6
 
[Queue , linked list , tree]
[Queue , linked list , tree][Queue , linked list , tree]
[Queue , linked list , tree]Nowrin Nishat
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence RelationNilaNila16
 
Chp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfChp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfSolomonMolla4
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dhrumil Panchal
 
Linear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfLinear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfssuser37b0e0
 
Stackpirt20170222
Stackpirt20170222Stackpirt20170222
Stackpirt20170222Sharon Liu
 
CEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docx
CEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docxCEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docx
CEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docxcravennichole326
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxjane3dyson92312
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxfestockton
 
Program Computing Project 4 builds upon CP3 to develop a program to .docx
Program Computing Project 4 builds upon CP3 to develop a program to .docxProgram Computing Project 4 builds upon CP3 to develop a program to .docx
Program Computing Project 4 builds upon CP3 to develop a program to .docxdessiechisomjj4
 

Similar to Sethi ullman persent (20)

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
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdf
 
Stacks and Queues with Linked List.pdf
Stacks and Queues with Linked List.pdfStacks and Queues with Linked List.pdf
Stacks and Queues with Linked List.pdf
 
Q
QQ
Q
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
Advance excel
Advance excelAdvance excel
Advance excel
 
[Queue , linked list , tree]
[Queue , linked list , tree][Queue , linked list , tree]
[Queue , linked list , tree]
 
Recurrence Relation
Recurrence RelationRecurrence Relation
Recurrence Relation
 
Chp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfChp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdf
 
Interview Preparation
Interview PreparationInterview Preparation
Interview Preparation
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
 
Linear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdfLinear Data Structures_SSD.pdf
Linear Data Structures_SSD.pdf
 
Stackpirt20170222
Stackpirt20170222Stackpirt20170222
Stackpirt20170222
 
CEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docx
CEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docxCEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docx
CEECNE 210—Statics SSEBE Mechanics Group Arizona State Un.docx
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Atan2
Atan2Atan2
Atan2
 
Program Computing Project 4 builds upon CP3 to develop a program to .docx
Program Computing Project 4 builds upon CP3 to develop a program to .docxProgram Computing Project 4 builds upon CP3 to develop a program to .docx
Program Computing Project 4 builds upon CP3 to develop a program to .docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Sethi ullman persent

  • 1. university of wah,wah cantt PAKISTAN. 1
  • 2. GROUP MEMBERS ANAS SATTI ZEESHAN AKRAM TOQEER QAYYUM university of wah,wah cantt PAKISTAN.
  • 3. History  In computer science, the Sethi–Ullman algorithm is an algorithm named after Ravi Sethi and Jeffrey D. Ullman , its inventors, for translating abstract syntax trees into machine code that uses as few instructions as possible. university of wah,wah cantt PAKISTAN.
  • 4. Cont..  Ravi Sethi (born 1947) is an Indian computer scientist retired from Bell Labs and president of Avaya Labs Research.  Jeffrey David "Jeff" Ullman (born November 22, 1942) is a computer scientist and professor at Stanford University university of wah,wah cantt PAKISTAN.
  • 5. Overview  When generating code for arithmetic expressions, the compiler has to decide which is the best way to translate the expression in terms of number of instructions used as well as number of registers needed to evaluate a certain subtree university of wah,wah cantt PAKISTAN.
  • 6. Cont...  The Sethi–Ullman algorithm fulfils the property of producing code which needs the least number of instructions possible as well as the least number of storage reference university of wah,wah cantt PAKISTAN.
  • 7. Optimal Code Generation  Generates the shortest sequence of instructions  Provably optimal algorithm (w.r.t. length of the sequence)  Suitable for expression trees  All computations are carried out in registers  Always computes the left subtree into a register and reuses it immediately university of wah,wah cantt PAKISTAN.
  • 8. Working  Traverse the abstract syntax tree in pre- or postorder  For every non-constant leaf node, assign a 1.  For every constant leaf node assign a 0.  For every non-leaf node n, assign the number of registers needed to evaluate the respective subtrees of n. university of wah,wah cantt PAKISTAN.
  • 9. • If the number of registers needed in the left subtree (l) are not equal to the number of registers needed in the right subtree (r), the number of registers needed for the current node n is max(l, r). If l == r, then the number of registers needed for the current node is l + 1. university of wah,wah cantt PAKISTAN.
  • 10. Code emission  If the number of registers needed to compute the left subtree of node n is bigger than the number of registers for the right subtree, then the left subtree is evaluated first university of wah,wah cantt PAKISTAN.
  • 11. Cont...  If the right subtree needs more registers than the left subtree, the right subtree is evaluated first accordingly. If both sub trees need equal as much registers, then the order of evaluation is irrelevant. university of wah,wah cantt PAKISTAN.
  • 12. Example AST traverse ( b +c +f *g)*(d+3),,, * / / + + / / / d 3 + * / / b c f g university of wah,wah cantt PAKISTAN.
  • 13. Cont...  Now we start traversing the tree (in preorder for now), assigning the number of registers needed to evaluate each subtree (note that the last summand in the expression is a constant) university of wah,wah cantt PAKISTAN.
  • 14. Cont... *2 / / +2 +1 / / / d1 30 +1 *1 / / b1 c0 f1 g0 university of wah,wah cantt PAKISTAN.
  • 15. Implementation  From this tree it can be seen that we need 2 registers to compute the left subtree of the '*', but only 1 register to compute the right subtree. Nodes 'c' and 'g' do not need registers for the following reasons:  If T is a tree leaf, then the number of registers to evaluate T is either 1 or 0 depending whether T is a left or a right subtree university of wah,wah cantt PAKISTAN.
  • 16. Cont...  Therefore we shall start to emit code for the left subtree first, because we might run into the situation that we only have 2 registers left to compute the whole expression  If we now computed the right subtree first (which needs only 1 register), we would then need a register to hold the result of the right subtree while computing the left subtree (which would still need 2 registers), therefore needing 3 registers concurrently university of wah,wah cantt PAKISTAN.
  • 17. Cont...  Computing the left subtree first needs 2 registers, but the result can be stored in 1, and since the right subtree needs only 1 register to compute, the evaluation of the expression can do with only 2 registers left. university of wah,wah cantt PAKISTAN.
  • 18. Uses  Minimizes register use  Minimizes execution time university of wah,wah cantt PAKISTAN.