🇮🇳 GATE CS & IT Engineering · subject
GATE CS & IT Engineering Compiler Design Syllabus
The Compiler Design syllabus for GATE CS & IT Engineering in full: 7 chapters and 3 topics, every one listed below, plus 50 Compiler Design flashcards with answers.
Compiler Design syllabus: all 7 chapters
Expand any chapter to see its topics and sub-topics.
-
Lexical analysis
overviewNo separate topics listed for this chapter.
-
Parsing
overviewNo separate topics listed for this chapter.
-
Syntax-directed translation
overviewNo separate topics listed for this chapter.
-
Runtime environments
overviewNo separate topics listed for this chapter.
-
Intermediate code generation
overviewNo separate topics listed for this chapter.
-
Local optimisation
overviewNo separate topics listed for this chapter.
-
Data flow analyses
3 topics- Constant propagation
- Liveness analysis
- Common sub expression elimination
GATE CS & IT Engineering Compiler Design flashcards — 50 questions with answers
What is constant propagation in compiler optimization?
Constant propagation is a data-flow optimization that replaces variables known to hold a constant value at a given program point with that constant, so the compiler can substitute the literal in place of the variable.
What is constant folding, and how does it relate to constant propagation?
Constant folding evaluates constant expressions at compile time (e.g., $3 \times 4 \to 12$). It works hand-in-hand with constant propagation: propagation supplies constant operands, and folding then computes the result, often enabling further propagation.
In the data-flow framework, what kind of analysis is constant propagation (direction and meet)?
Constant propagation is a forward data-flow analysis. Its lattice meet (confluence) operator combines values from predecessors, mapping conflicting constants to NAC (Not A Constant / $\bot$).
What are the three categories of values in the constant-propagation lattice for a single variable?
$\top$ (UNDEF — not yet known / no information), a specific constant $c$, and $\bot$ (NAC — Not A Constant, meaning the variable may hold different values on different paths).
Why is the constant-propagation lattice considered to have infinite height (and a non-distributive framework)?
Because there are infinitely many possible constants $c$, the per-variable lattice has the chain $\top > c > \bot$ but infinitely many incomparable constant elements. The framework is also non-distributive, so the MOP solution can be more precise than the MFP (iterative) solution.
Define the meet rules for combining two constant-propagation values $v_1 \sqcap v_2$.
$\top \sqcap v = v$; $\bot \sqcap v = \bot$; $c \sqcap c = c$ (same constant); and $c_1 \sqcap c_2 = \bot$ when $c_1 \neq c_2$ (conflicting constants give NAC).
At a control-flow merge point, if variable $x$ is $5$ along one path and $7$ along another, what value does constant propagation assign to $x$?
$\bot$ (NAC). Since the two incoming constants $5 \neq 7$ disagree, $x$ cannot be treated as a constant after the merge.
Why is constant propagation undecidable in the fully general (exact) case?
Determining whether a variable always holds a particular constant at a point can depend on whether certain branches are ever taken, which reduces to undecidable problems (e.g., the halting problem). Compilers therefore compute a safe, conservative approximation.
What is the difference between the MOP and MFP solutions for constant propagation, and which is computed in practice?
MOP (Meet Over all Paths) is the ideal solution meeting data-flow values over every path; MFP (Maximum Fixed Point) is what the iterative algorithm computes. Because constant propagation is non-distributive, $\text{MFP} \leq \text{MOP}$ (MFP is conservative/less precise). Compilers compute MFP.
Give the constant-propagation transfer function for an assignment $x = y + z$.
If $y = c_1$ and $z = c_2$ are both constants, then $x = c_1 + c_2$ (folded). If either operand is $\bot$ (NAC), then $x = \bot$. If an operand is $\top$, $x$ remains $\top$ until that operand is resolved.
What is conditional constant propagation (sparse conditional constant propagation, SCCP)?
SCCP combines constant propagation with dead-code/unreachable-branch detection: it propagates constants while simultaneously discovering which branches are unreachable (because the condition folds to a constant), making it strictly more powerful than doing the two optimizations separately.
In SSA form, why is constant propagation easier and more precise?
In SSA each variable has exactly one definition, so the constant value of a variable is unambiguous; $\phi$-functions cleanly express merges. This enables efficient sparse algorithms like Wegman–Zadeck SCCP that work on def-use chains rather than re-iterating over all program points.
What optimization opportunities does constant propagation typically enable downstream?
It enables constant folding, dead-code elimination (branches with constant conditions), strength reduction, algebraic simplification, and unreachable-code removal, often cascading to expose further constants.
After $a = 5$, the statement $b = a + 3$ is encountered. What does constant propagation (with folding) produce for $b$?
It substitutes $a = 5$ to get $b = 5 + 3$, then folds to $b = 8$.
What is liveness analysis (live-variable analysis)?
Liveness analysis is a data-flow analysis that determines, for each program point, the set of variables that are live — i.e., that hold a value which may be used along some path before being redefined.
Formally, when is a variable said to be live at a program point?
A variable $x$ is live at point $p$ if there exists a path from $p$ to a use of $x$ that contains no redefinition of $x$ between $p$ and that use. Otherwise $x$ is dead at $p$.
What is the direction and meet operator of liveness analysis?
Liveness is a backward data-flow analysis (information flows from uses back toward definitions), and its meet/confluence operator is set union ($\cup$).
State the data-flow equations for liveness analysis.
$$IN[B] = use[B] \cup (OUT[B] - def[B])$$ $$OUT[B] = \bigcup_{S \in succ(B)} IN[S]$$ with the boundary condition $OUT[\text{EXIT}] = \varnothing$.
In liveness analysis, what do $use[B]$ and $def[B]$ (gen and kill) represent for a basic block $B$?
$use[B]$ (gen) is the set of variables used in $B$ before any redefinition within $B$; $def[B]$ (kill) is the set of variables assigned (defined) in $B$ before any use of them in $B$.
What is the initialization and boundary condition for the iterative liveness algorithm?
Initialize $IN[B] = OUT[B] = \varnothing$ for all blocks, and set the boundary $OUT[\text{EXIT}] = \varnothing$. Then iterate the backward equations until no set changes (fixed point).
Show the other 30 Compiler Design flashcards
For a single statement $s:\ x = y + z$, give the live-variable transfer function $IN[s]$ in terms of $OUT[s]$.
$$IN[s] = (OUT[s] - \{x\}) \cup \{y, z\}$$ — $x$ is killed (defined), and $y, z$ are generated (used).
What is the relationship between liveness analysis and dead-code elimination?
If the variable defined by a statement is not live immediately after that statement (and the statement has no side effects), the assignment is dead and can be removed. Liveness identifies exactly such useless definitions.
How is liveness analysis used in register allocation?
Liveness defines live ranges of variables; two variables that are simultaneously live interfere. The interference graph is built from this, and graph coloring assigns registers so that interfering variables get different registers.
When do two variables 'interfere' in the interference graph used for register allocation?
Two variables interfere if their live ranges overlap — i.e., there is a point where both are simultaneously live — so they cannot share the same register.
Why does liveness analysis use the may (union) meet rather than must (intersection)?
A variable is live if it is used along some (any) future path, not all paths. Union over successors captures this 'may be used' (existential) property, making liveness a 'may' analysis.
What is the time complexity bound for the iterative liveness analysis, and why does it terminate?
It terminates because each iteration only adds variables to the monotone increasing IN/OUT sets, bounded by the finite variable set. With $n$ nodes and $v$ variables, a bit-vector iterative solver runs in roughly $O(n^2 v)$ worst case, often near-linear in practice.
In liveness analysis, after computing fixed point, $OUT[B] = \{a, b\}$ and $B$ contains only $c = a + 1$. What is $IN[B]$?
$def[B] = \{c\}$, $use[B] = \{a\}$. $IN[B] = use[B] \cup (OUT[B] - def[B]) = \{a\} \cup (\{a,b\} - \{c\}) = \{a, b\}$.
What distinguishes a 'live' variable from a 'reaching' definition conceptually?
Liveness is a backward analysis about future uses of a variable's value; reaching definitions is a forward analysis about which definitions of a variable may reach a point. They are dual in direction and ask different questions.
What is common subexpression elimination (CSE)?
CSE is an optimization that detects expressions computed more than once with the same operand values, and replaces redundant recomputations by reusing the previously computed result (stored in a temporary).
When is an expression $x\ op\ y$ called a common subexpression at a point?
It is a common subexpression if it was previously computed, and the values of $x$ and $y$ have not changed (no redefinition of $x$ or $y$) since that previous computation — so the earlier result is still valid.
What is an 'available expression', and how does it relate to CSE?
An expression $e$ is available at point $p$ if on every path from entry to $p$, $e$ has been computed and none of its operands redefined afterward. Available-expressions analysis identifies expressions safe to reuse, which is the basis for global CSE.
What are the direction and meet operator of available-expressions analysis?
Available expressions is a forward data-flow analysis with set intersection ($\cap$) as the meet operator (a 'must' analysis — available on all paths).
State the data-flow equations for available expressions.
$$OUT[B] = e\_gen[B] \cup (IN[B] - e\_kill[B])$$ $$IN[B] = \bigcap_{P \in pred(B)} OUT[P]$$ with $IN[\text{ENTRY}] = \varnothing$ and all other $OUT$ initialized to the universal set $U$.
In available-expressions analysis, what do $e\_gen[B]$ and $e\_kill[B]$ mean?
$e\_gen[B]$ is the set of expressions evaluated in $B$ and not subsequently killed in $B$ (their operands not redefined afterward in $B$); $e\_kill[B]$ is the set of expressions whose operands are redefined (killed) in $B$.
Why is the initialization for available expressions the universal set $U$ (not empty) for interior blocks?
Because it is a 'must' / intersection analysis: to find the maximum fixed point, interior $OUT$ sets start optimistically as the full universe $U$ and shrink via intersection. Starting empty would give the trivial all-empty (least) solution incorrectly.
Distinguish local CSE from global CSE.
Local CSE eliminates redundant expressions within a single basic block (using a value/expression table during a single pass). Global CSE works across basic blocks using available-expressions data-flow analysis over the whole CFG.
How is a common subexpression eliminated once detected? Show the transformation.
Replace the first occurrence $t = b + c;\ x = t$ and a later redundant $y = b + c$ with $y = t$. A temporary $t$ holds the value: instead of recomputing $b+c$, reuse $t$ (provided $b, c$ unchanged).
What is the difference between common subexpression elimination and copy propagation?
CSE removes redundant computations of the same expression by reusing a stored result; copy propagation replaces uses of a variable $y$ with $x$ after a copy $y = x$. CSE often introduces temporaries/copies that copy propagation then cleans up.
Why can CSE sometimes increase register pressure or even degrade performance?
Storing a reused value in a temporary keeps it live across the gap between computations, lengthening live ranges and possibly forcing spills. If recomputation is cheaper than holding the value in a register, CSE can be counterproductive.
What role does a Directed Acyclic Graph (DAG) play in local common subexpression elimination?
A DAG representation of a basic block shares identical subexpressions as a single node; when building it, an existing node is reused instead of created, automatically detecting and eliminating local common subexpressions.
What is the difference between syntactic (lexical) and value-based (semantic) common subexpressions?
Syntactic CSE matches expressions textually (same operator and same operand names). Value-based CSE (e.g., value numbering / GVN) matches expressions that compute the same value even if written differently, catching more redundancies.
What is value numbering and how does it support CSE?
Value numbering assigns a unique number to each computed value; expressions that map to the same value number are equivalent. It detects common subexpressions (and constants/copies) by hash-lookup, forming a powerful basis for CSE.
Compare the meet operators and what they imply for available expressions vs. live variables.
Available expressions uses intersection ($\cap$, must/all-paths, forward); live variables uses union ($\cup$, may/some-path, backward). The meet reflects whether a property must hold on all paths or may hold on some path.
Fill the four-way classification: for (Reaching Definitions, Available Expressions, Live Variables, Busy/Anticipated Expressions), give direction and meet.
Reaching Definitions: forward, $\cup$. Available Expressions: forward, $\cap$. Live Variables: backward, $\cup$. Busy (Very Busy/Anticipated) Expressions: backward, $\cap$.
Is available-expressions analysis a 'may' or 'must' analysis, and what does that guarantee for CSE safety?
It is a 'must' analysis (intersection). This guarantees the expression's value is available on every path reaching the point, so reusing the precomputed result is always safe (sound).
In available expressions, block $B$ computes $t = b + c$ and does not redefine $b$ or $c$ afterward. What is $e\_gen[B]$ for this expression?
$e\_gen[B] = \{\,b + c\,\}$, since $b + c$ is evaluated in $B$ and its operands are not killed afterward within $B$.
If an expression $b + c$ is available at a point but $b$ is redefined just before, is $b + c$ still available? Explain.
No. Redefining $b$ kills $b + c$ (it is in $e\_kill$), so the previously computed value is stale. The expression must be recomputed; it is not safe for CSE at that point.
What is the key practical reason all three—constant propagation, liveness, and CSE—are framed as data-flow analyses?
They all compute facts that hold along control-flow paths by solving iterative fixed-point equations over a lattice. The unifying monotone data-flow framework (direction, meet, transfer functions) lets the same iterative algorithm solve each, differing only in lattice, direction, and meet.
Why does liveness analysis converge to a unique fixed point with the iterative algorithm?
Because the transfer functions are monotone over a finite lattice (bounded variable set) and sets only grow (for union/may analysis). Monotonicity plus finite height guarantees termination at the maximum fixed point, which is unique.
Give one example each where constant propagation, liveness, and CSE respectively reduce executed work.
Constant propagation: replaces $r = n \times 1$ with $r = n$ after folding, removing a multiply. Liveness: removes a dead assignment $t = a + b$ whose $t$ is never used. CSE: replaces a second $b + c$ with a stored temporary $t$, removing a redundant addition.
GATE CS & IT Engineering Compiler Design FAQ
What is in the GATE CS & IT Engineering Compiler Design syllabus?
GATE CS & IT Engineering Compiler Design is split into 7 chapters: Lexical analysis, Parsing, Syntax-directed translation, Runtime environments, Intermediate code generation, Local optimisation and Data flow analyses. Together they contain 3 topics.
How many chapters are in GATE CS & IT Engineering Compiler Design?
7 chapters, containing 3 topics. The largest chapter is Data flow analyses, with 3 topics.
Are there flashcards for GATE CS & IT Engineering Compiler Design?
Yes — a 50-card Compiler Design deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.