Compilers

Which describes a basic block?

  1. AA run of instructions with no branches in or out midway
  2. BAll the instructions contained in a single function, gathered together
  3. CA loop body replicated several times to reduce the number of iterations
Show answer and explanation

Answer: A. A run of instructions with no branches in or out midway

A basic block is an instruction sequence entered only at its first instruction and exited only at its last; once started, execution neither leaves nor enters partway through. Blocks are delimited at branch targets and right after branch instructions. Since execution order within a block is fixed, local optimization is easy, and a control-flow graph with blocks as nodes represents overall flow. A function usually consists of many basic blocks, and replicating a loop body is loop unrolling.

  • A. Correct. It is entered only at the start and exited only at the end.
  • B. A function usually consists of many basic blocks.
  • C. Replicating a loop body is loop unrolling.
Practice this topic Back to topic

More Compilers questions

  1. In a control-flow graph, what do the nodes and edges represent?
  2. Which is a characteristic of an IR in SSA form?
  3. Converting the code above to SSA form inserts an expression like "x3 = φ(x1, x2)" after the if statement. What does the φ function do?
  4. Which is an example of constant folding by a compiler?
  5. After repeatedly applying constant propagation and constant folding to the code above, what does it finally become?