Code Generation and Optimization

    Last Updated :
    Discuss
    Comments

    Question 1

    Match the description of several parts of a classic optimizing compiler in List - I, with the names of those parts in List - II: Capture11

    • (1)

    • (2)

    • (3)

    • (4)

    Question 2

    Consider the following source code :

    c = a + b
    d = c
    c = c – e
    a = d – e
    b = b * e
    b = d/b

    Which of the following is correct optimization of given code?

    • c = a + b
            t = b * e
            a = d – e
            b = d/t
            c = a
    • c = a + b
            d = c
            c = c – e
            a = d – e
            b = d/b
    • d = c
           c = c – e
           a = d – e
           b = b * e
           b = d/b
    • None of the above

    Question 3

    Consider the following expression
    u*v+a-b*c
    Which one of the following corresponds to a static single assignment from the above expressions
    • x1 = a - b y1 = p * c x2 = u * v y2 = p + q

    • x 1 = a - b y1 = x2 * c x3 = u * v y2 = x4 + y3

    • x1 = a - b y2 = x1 * c x2 = u * v y3 = x2 + y2

    • p = a - b q = p * c p = u * v q = p + q

    Question 4

    Consider the code segment

    int i, j, x, y, m, n;
    n=20;
    for (i = 0, i < n; i++)
    {
    for (j = 0; j < n; j++)
    {
    if (i % 2)
    {
    x + = ((4*j) + 5*i);
    y += (7 + 4*j);
    }
    }
    }
    m = x + y;

    Which one of the following is false

    • The code contains loop invariant computation

    • There is scope of common sub-expression elimination in this code

    • There is scope of strength reduction in this code

    • There is scope of dead code elimination in this code

    Question 5

    Peephole optimization is form of

    • Loop optimization

    • Local optimization

    • Constant folding

    • Data flow analysis

    Question 6

    Which of the following is NOT represented in a subroutine's activation record frame for a stack-based programming language?

    • Values of local variables

    • Return address

    • Heap area

    • Information needed to access non local variables

    Question 7

    In compiler terminology reduction in strength means

    • Replacing run time computation by compile time computation

    • Removing loop invariant computation

    • Removing common subexpressions

    • replacing a costly operation by a relatively cheaper one

    Question 8

    Which of the following statements about peephole optimization is False?

    • It is applied to a small part of the code

    • It can be used to optimize intermediate code

    • To get the best out of this, it has to be applied repeatedly

    • It can be applied to the portion of the code that is not contiguous

    Question 9

    The use of multiple register windows with overlap causes a reduction in the number of memory accesses for I. Function locals and parameters II. Register saves and restores III. Instruction fetches

    • I only

    • II only

    • III only

    • I, II and III

    Question 10

    Substitution of values for names (whose values are constants) is done in

    • Local optimization

    • Loop optimization

    • Constant folding

    • Strength reduction

    There are 38 questions to complete.

    Take a part in the ongoing discussion