Directed Acyclic graph can be used
Directed Acyclic graph can be used
Answer: C. both a and b — Answer: Directed Acyclic Graphs (DAGs) are used to represent expressions within a basic block, enabling optimization. Key ideas: Eliminate common…
- A.
to generate the optimized 3 address code
- B.
to eliminate the common subexpression elimination
- C.
both a and b
- D.
none of the above
Attempted by 290 students.
Show answer & explanation
Correct answer: C
Answer: Directed Acyclic Graphs (DAGs) are used to represent expressions within a basic block, enabling optimization.
Key ideas:
Eliminate common subexpressions — identical expressions are represented by a single DAG node, so repeated computations are detected and computed once.
Generate optimized three-address code — traverse the DAG and emit code only for distinct computations, reusing results from shared nodes to reduce temporaries and instructions.
Example:
Original code: x = a + b; y = a + b;
Optimized using a DAG: t1 = a + b; x = t1; y = t1