SlideShare a Scribd company logo
3
Most read
5
Most read
11
Most read
The Dag Representation of Basic
Blocks
PRESENTED BY
A.SHABEEN TAJ
BP150518
CONTENTS
• Introduction
• A DAG with following labels on nodes
• Dag Construction
• Constructing a DAG
• Applications of Dags
• Arrays, Pointers and Procedure calls
• Rules
Introduction:
• Directed Acyclic Graphs (dags) are useful data
structures for implementing transformations on basic
blocks.
• A dag gives a picture of how the value computed by
each statement in a basic block is used in subsequent
statements of the block.
• Constructing a dag from three- address statements is a
good way of determining common sub expressions
within a block, determining which names are used
inside the block but evaluate outside the block, and
determining which statements of the block have their
computed value outside the block.
A dag with following labels on
nodes:
1. Levels are labeled by unique identifiers, either variable
names or constants.
2. Interior nodes are labeled by an operator symbol.
3. Nodes are also optionally given by a sequence of
identifiers for labels. The intention is that interior nodes
represent computed values, and the identifiers labeling a
node are deemed to have that value.
It is important not to confuse dags with flow
graphs. Each node of a flow graph can be
represented by a dag, since each node of the flow
graph stands for a basic block.
The dag representation of basic blocks
Dag Construction:
• To construct a dag: When we see a statement
of the form x:=y+z,
Y and z – leaves / interior nodes.
• When we create labeled + => has two children
• Y – left child and z- right child and its label is
x.
• If the another node has same value y+z,
instead of adding new node, existing node can
be used as label x.
Two details should be mentioned:
• First, if x had previously labeled some other
node, remove that label, since the “current”
value of x is the node created.
• Second, for assignment x:=y, do not create a
new node, but append x to the list of names on
the node for the “current” value of y.
Constructing a dag:
• Input: A basic block
• Output: It has following information,]
1. A label for each node. For leaves label is an identifier
(constants permitted) and for interior nodes, an
operator symbol.
2. For each node a list of attached identifiers(constants
not permitted).
• Method: Data structures are available to create nodes
with one or two children distinguishing left and right.
• To create a linked list of attached identifiers for each
node.
• The dag construction has the following
process: Initially assume, no nodes and nodes
is undefined for all arguments.
• Suppose “current” three address statements (i)
x:= y op z (ii) x:=op y (iii) x:=y.
• Treat a relational operator like if i<=20 goto
case (i), with x undefined.
1. If node(y) is undefined, create a leaf labeled
y, and let node(y) be this node. In case(i), If
node(z) is undefined, create a leaf labeled z,
and let the leaf node(z).
2. In case (i), determine if there is a node labeled op,
whose leaf child is node(y) and right child is
node(z). If not, create such a node and n be the node
found or created. In case (ii), determine whether ther
is node labeled op, whose lone child is node(y). If
not, create such a node and n be the node found or
created. In case(iii), let n be node(y)
3. Delete x from the list of attached identifiers for node
(x). Append x to list of attached identifiers for node
n found in (2) and set node(x) to n.
Applications of dags:
1. Automatically detect common sub
expressions.
2. Can determine which identifiers have their
values used in the block.
3. Can determine which statements compute
value that could be used outside the block.
Example:9.10
• Let us reconstruct a basic block from the dag of
fig 9.16, ordering nodes in the same order as they
were created. So the first reconstructed statement
is,
t1:=4*I
• Second, statement constructed as,
t2:=a[t1]
• The next is labeled as t4,
t4:=b[t1]
• Then, t5 is constructed as,
t5:=t2*t4
• For label t6 and prod, like t3, temporary t6
disappears. So the generated statement is,
prod:=prod+t5
• Similarly, choose I rather than t7 to carry the vale
i+1. The last two statements generated are,
i:=i+1
if i<=20 goto (1)
• Reduced ten statements to seven using common
sub expression (dag advantage) and by
eliminating unnecessary assignments.
Arrays, Pointers and Procedure
Calls:
• Consider the block:
X:=a[i] a[j]:=y z:=a[i] (9.5)
• Construct dag a[i] would become common sub
expression and optimized as
X:=a[i] z:=x a[j]:=y (9.6)
However, (9.5)and (9.6) compute different
values for z in case i=j and y!=a[i].
Rules:
• Let us introduce certain edges n->m in dag that do
not indicate that m is an argument of n, but rather
that evaluation of n must follow evaluation of m
in any computation of the dag. The rules are:
1. Any evaluation of or assignment to an element
of array a must follow previous assignment to an
element of that array if there is one.
2. Any assignment to an element of array a must
follow previous evaluation of a.
3. Any use of any identifier must follow the
previous procedure call or indirect assignment
through a pointer if there is one.
4. Any procedure call or indirect assignment
through a pointer must follow all previous
evaluations of any identifier.
That is, when reordering code, uses of an
array a may not cross each other, and no
statement may cross a procedure call or an
assignment through a pointer.
Any Queries:
???
• Thank you

More Related Content

PPTX
Code Optimization
PPTX
Basic blocks and control flow graphs
PPTX
Translation of expression(copmiler construction)
PPT
Lecture 1 - Lexical Analysis.ppt
PDF
Syntax directed translation
PPTX
Data cube computation
PDF
Classes and Objects
PPTX
Input-Buffering
Code Optimization
Basic blocks and control flow graphs
Translation of expression(copmiler construction)
Lecture 1 - Lexical Analysis.ppt
Syntax directed translation
Data cube computation
Classes and Objects
Input-Buffering

What's hot (20)

PPTX
Lecture 14 run time environment
PDF
Syntax Directed Definition and its applications
PDF
Code optimization in compiler design
PPTX
Analysis and Design of Algorithms
PPTX
contiguous memory allocation.pptx
PPTX
Dag representation of basic blocks
PPTX
Three Address code
PDF
Intermediate code generation in Compiler Design
PDF
Algorithms Lecture 7: Graph Algorithms
PPTX
Validation based protocol
PPTX
Three address code In Compiler Design
PPTX
COMPILER DESIGN
PPTX
Generic types and collections GUIs.pptx
PPTX
Deadlock dbms
PPTX
Non- Deterministic Algorithms
PDF
Monitors
PPTX
Syntax Analysis in Compiler Design
PPTX
Directed Acyclic Graph Representation of basic blocks
PDF
Token, Pattern and Lexeme
PPTX
Heuristics Search Techniques in AI
Lecture 14 run time environment
Syntax Directed Definition and its applications
Code optimization in compiler design
Analysis and Design of Algorithms
contiguous memory allocation.pptx
Dag representation of basic blocks
Three Address code
Intermediate code generation in Compiler Design
Algorithms Lecture 7: Graph Algorithms
Validation based protocol
Three address code In Compiler Design
COMPILER DESIGN
Generic types and collections GUIs.pptx
Deadlock dbms
Non- Deterministic Algorithms
Monitors
Syntax Analysis in Compiler Design
Directed Acyclic Graph Representation of basic blocks
Token, Pattern and Lexeme
Heuristics Search Techniques in AI
Ad

Viewers also liked (20)

PPTX
Peephole optimization techniques in compiler design
PPTX
Run time administration
PPT
Chapter 6 intermediate code generation
PPT
Query processing-and-optimization
PPTX
Back patching
PPTX
Compiler Optimization Presentation
PPT
Lecture 16 17 code-generation
PPTX
Basic Blocks and Flow Graphs
PPTX
Code generation
PPT
Chapter Seven(2)
PDF
Control Flow Analysis
PPTX
Compiler Chapter 1
PPT
11. Storage and File Structure in DBMS
PPTX
Intermediate code- generation
PPTX
Symbol table design (Compiler Construction)
PDF
CBSE XII Boolean Algebra
PDF
Compiler unit 4
PPTX
Lecture 11 semantic analysis 2
PPT
Module 11
Peephole optimization techniques in compiler design
Run time administration
Chapter 6 intermediate code generation
Query processing-and-optimization
Back patching
Compiler Optimization Presentation
Lecture 16 17 code-generation
Basic Blocks and Flow Graphs
Code generation
Chapter Seven(2)
Control Flow Analysis
Compiler Chapter 1
11. Storage and File Structure in DBMS
Intermediate code- generation
Symbol table design (Compiler Construction)
CBSE XII Boolean Algebra
Compiler unit 4
Lecture 11 semantic analysis 2
Module 11
Ad

Similar to The dag representation of basic blocks (20)

PPTX
Group discussion Presentation uit rgpv
PDF
Code optimization lecture
PDF
INTERMEDIATE CODE GENERTION-CD UNIT-3.pdf
PPTX
Compiler Design Unit 3
PPT
unit-5.pptvshvshshhshsjjsjshhshshshhshsj
PPTX
Optimization of basic blocks
PPT
Code Generations - 1 compiler design.ppt
PPT
Compiler-Design-Intermediate-code-generation.ppt
PPT
458237.-Compiler-Design-Intermediate-code-generation.ppt
PPT
456589.-Compiler-Design-Code-Generation (1).ppt
PPT
Intermediate code generation
PPTX
Direct Acyclic Graph (DAG)
DOC
Compiler notes--unit-iii
PPT
PRESENTATION ON DATA STRUCTURE AND THEIR TYPE
PPT
456589.-Compiler-Design-Code-Generation (1).ppt
PPTX
Lecture 12 intermediate code generation
PDF
Compiler unit 5
PDF
Intermediate code generation
PPTX
UNIT V - Compiler Design notes power point presentation
PPTX
DAG Representation of basic blocks & Peephole Optimization
Group discussion Presentation uit rgpv
Code optimization lecture
INTERMEDIATE CODE GENERTION-CD UNIT-3.pdf
Compiler Design Unit 3
unit-5.pptvshvshshhshsjjsjshhshshshhshsj
Optimization of basic blocks
Code Generations - 1 compiler design.ppt
Compiler-Design-Intermediate-code-generation.ppt
458237.-Compiler-Design-Intermediate-code-generation.ppt
456589.-Compiler-Design-Code-Generation (1).ppt
Intermediate code generation
Direct Acyclic Graph (DAG)
Compiler notes--unit-iii
PRESENTATION ON DATA STRUCTURE AND THEIR TYPE
456589.-Compiler-Design-Code-Generation (1).ppt
Lecture 12 intermediate code generation
Compiler unit 5
Intermediate code generation
UNIT V - Compiler Design notes power point presentation
DAG Representation of basic blocks & Peephole Optimization

Recently uploaded (20)

PDF
1_English_Language_Set_2.pdf probationary
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
Introduction to Building Materials
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
Computer Architecture Input Output Memory.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
1_English_Language_Set_2.pdf probationary
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Hazard Identification & Risk Assessment .pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
FORM 1 BIOLOGY MIND MAPS and their schemes
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
Introduction to Building Materials
What if we spent less time fighting change, and more time building what’s rig...
IGGE1 Understanding the Self1234567891011
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
A powerpoint presentation on the Revised K-10 Science Shaping Paper
AI-driven educational solutions for real-life interventions in the Philippine...
Share_Module_2_Power_conflict_and_negotiation.pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Computer Architecture Input Output Memory.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS

The dag representation of basic blocks

  • 1. The Dag Representation of Basic Blocks PRESENTED BY A.SHABEEN TAJ BP150518
  • 2. CONTENTS • Introduction • A DAG with following labels on nodes • Dag Construction • Constructing a DAG • Applications of Dags • Arrays, Pointers and Procedure calls • Rules
  • 3. Introduction: • Directed Acyclic Graphs (dags) are useful data structures for implementing transformations on basic blocks. • A dag gives a picture of how the value computed by each statement in a basic block is used in subsequent statements of the block. • Constructing a dag from three- address statements is a good way of determining common sub expressions within a block, determining which names are used inside the block but evaluate outside the block, and determining which statements of the block have their computed value outside the block.
  • 4. A dag with following labels on nodes: 1. Levels are labeled by unique identifiers, either variable names or constants. 2. Interior nodes are labeled by an operator symbol. 3. Nodes are also optionally given by a sequence of identifiers for labels. The intention is that interior nodes represent computed values, and the identifiers labeling a node are deemed to have that value. It is important not to confuse dags with flow graphs. Each node of a flow graph can be represented by a dag, since each node of the flow graph stands for a basic block.
  • 6. Dag Construction: • To construct a dag: When we see a statement of the form x:=y+z, Y and z – leaves / interior nodes. • When we create labeled + => has two children • Y – left child and z- right child and its label is x. • If the another node has same value y+z, instead of adding new node, existing node can be used as label x.
  • 7. Two details should be mentioned: • First, if x had previously labeled some other node, remove that label, since the “current” value of x is the node created. • Second, for assignment x:=y, do not create a new node, but append x to the list of names on the node for the “current” value of y.
  • 8. Constructing a dag: • Input: A basic block • Output: It has following information,] 1. A label for each node. For leaves label is an identifier (constants permitted) and for interior nodes, an operator symbol. 2. For each node a list of attached identifiers(constants not permitted). • Method: Data structures are available to create nodes with one or two children distinguishing left and right. • To create a linked list of attached identifiers for each node.
  • 9. • The dag construction has the following process: Initially assume, no nodes and nodes is undefined for all arguments. • Suppose “current” three address statements (i) x:= y op z (ii) x:=op y (iii) x:=y. • Treat a relational operator like if i<=20 goto case (i), with x undefined. 1. If node(y) is undefined, create a leaf labeled y, and let node(y) be this node. In case(i), If node(z) is undefined, create a leaf labeled z, and let the leaf node(z).
  • 10. 2. In case (i), determine if there is a node labeled op, whose leaf child is node(y) and right child is node(z). If not, create such a node and n be the node found or created. In case (ii), determine whether ther is node labeled op, whose lone child is node(y). If not, create such a node and n be the node found or created. In case(iii), let n be node(y) 3. Delete x from the list of attached identifiers for node (x). Append x to list of attached identifiers for node n found in (2) and set node(x) to n.
  • 11. Applications of dags: 1. Automatically detect common sub expressions. 2. Can determine which identifiers have their values used in the block. 3. Can determine which statements compute value that could be used outside the block.
  • 12. Example:9.10 • Let us reconstruct a basic block from the dag of fig 9.16, ordering nodes in the same order as they were created. So the first reconstructed statement is, t1:=4*I • Second, statement constructed as, t2:=a[t1] • The next is labeled as t4, t4:=b[t1]
  • 13. • Then, t5 is constructed as, t5:=t2*t4 • For label t6 and prod, like t3, temporary t6 disappears. So the generated statement is, prod:=prod+t5 • Similarly, choose I rather than t7 to carry the vale i+1. The last two statements generated are, i:=i+1 if i<=20 goto (1) • Reduced ten statements to seven using common sub expression (dag advantage) and by eliminating unnecessary assignments.
  • 14. Arrays, Pointers and Procedure Calls: • Consider the block: X:=a[i] a[j]:=y z:=a[i] (9.5) • Construct dag a[i] would become common sub expression and optimized as X:=a[i] z:=x a[j]:=y (9.6) However, (9.5)and (9.6) compute different values for z in case i=j and y!=a[i].
  • 15. Rules: • Let us introduce certain edges n->m in dag that do not indicate that m is an argument of n, but rather that evaluation of n must follow evaluation of m in any computation of the dag. The rules are: 1. Any evaluation of or assignment to an element of array a must follow previous assignment to an element of that array if there is one. 2. Any assignment to an element of array a must follow previous evaluation of a.
  • 16. 3. Any use of any identifier must follow the previous procedure call or indirect assignment through a pointer if there is one. 4. Any procedure call or indirect assignment through a pointer must follow all previous evaluations of any identifier. That is, when reordering code, uses of an array a may not cross each other, and no statement may cross a procedure call or an assignment through a pointer.