Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering

The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE) PDF Download

THE DAG REPRESENTATION FOR BASIC BLOCKS

•   A DAG for a basic block is a directed acyclic graph with the following labels on nodes:

1.   Leaves 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 a sequence of identifiers for labels to store the computed values.

•   DAGs are useful data structures for implementing transformations on basic blocks.

•   It gives a picture of how the value computed by a statement is used in subsequent statements.

•   It provides a good way of determining common sub - expressions.

 

Algorithm for construction of DAG

Input: A basic block

Output: A DAG for the basic block containing the following information:

1.    A label for each node. For leaves, the label is an identifier. For interior nodes, an operator symbol.

2.   For each node a list of attached identifiers to hold the computed values. Case (i) x : = y OP z Case (ii) x : = OP y

Case (iii) x : = y

Method:

Step 1:

If y is undefined then create node(y).

If z is undefined, create node(z) for case(i).

 

Step 2:

For the case(i), create a node(OP) whose left child is node(y) and right child is node(z). (Checking for common sub expression). Let n be this node.

For case(ii), determine whether there is node(OP) with one child node(y). If not create such a node.

For case(iii), node n will be node(y).

 

Step 3:

Delete x from the list of identifiers for node(x). Append x to the list of attached identifiers for the node n found in step 2 and set node(x) to n.

Example: Consider the block of three- address statements in Fig 4.6

 

Stages in DAG Construction

The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE) The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)
Fig. 4.5 Steps in DAG construction process

The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)

 Fig. 4.6 Code Block

 

Application of DAGs:

1.   We can automatically detect common sub expressions.

2.   We can determine which identifiers have their values used in the block.

3.   We can determine which statements compute values that could be used outside the block.

The document The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE) is a part of Computer Science Engineering (CSE) category.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

FAQs on The Dag Representation For Basic Blocks - Code Generation, Computer Science and IT Engineering - Computer Science Engineering (CSE)

1. What is the Dag representation for basic blocks?
Ans. The Dag representation for basic blocks is a data structure that represents the control flow of a program by using directed acyclic graphs (DAGs). It captures the dependencies between instructions within a basic block and allows for efficient code generation and optimization.
2. How does the Dag representation improve code generation?
Ans. The Dag representation improves code generation by providing a compact and efficient way to represent the control flow of a program. It allows for the detection of common subexpressions and redundant computations, which can be eliminated to generate optimized code. Additionally, the Dag representation facilitates the identification of opportunities for instruction scheduling and register allocation.
3. What are the benefits of using DAGs for code generation?
Ans. Using DAGs for code generation offers several benefits. Firstly, it allows for efficient representation and manipulation of the control flow, enabling optimization techniques such as constant folding, common subexpression elimination, and dead code elimination. Secondly, DAGs provide a way to express complex dependencies between instructions, allowing for more accurate and efficient code generation. Finally, DAGs enable the detection and exploitation of opportunities for instruction scheduling, which can further improve the performance of the generated code.
4. How are DAGs constructed for basic blocks?
Ans. DAGs for basic blocks are constructed by analyzing the dependencies between instructions within the block. Each instruction is represented as a node in the DAG, and the dependencies between instructions are represented as edges. These dependencies can be data dependencies, control dependencies, or memory dependencies. By traversing the basic block and identifying the dependencies between instructions, a DAG can be constructed that accurately represents the control flow and dependencies within the block.
5. Can DAG representation be used for optimizing code?
Ans. Yes, the DAG representation can be used for optimizing code. The DAG representation allows for the detection and elimination of common subexpressions, which can reduce redundant computations and improve the efficiency of the generated code. Additionally, DAGs enable other optimization techniques such as constant folding, dead code elimination, and instruction scheduling. By analyzing the DAG representation and applying these optimization techniques, the generated code can be significantly improved in terms of performance and efficiency.
Download as PDF

Top Courses for Computer Science Engineering (CSE)

Related Searches

video lectures

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

Free

,

MCQs

,

Sample Paper

,

mock tests for examination

,

The Dag Representation For Basic Blocks - Code Generation

,

Exam

,

Previous Year Questions with Solutions

,

Important questions

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

ppt

,

Objective type Questions

,

Extra Questions

,

Viva Questions

,

practice quizzes

,

Summary

,

The Dag Representation For Basic Blocks - Code Generation

,

pdf

,

shortcuts and tricks

,

Semester Notes

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

past year papers

,

study material

,

The Dag Representation For Basic Blocks - Code Generation

;