KatInterview

Compiler Instruction Scheduling for a Multi-Issue VLIW Processor

System DesignModel answer
HardModel answerSystem Designcompiler-backendinstruction-schedulingvliw

Last updated

Design an instruction scheduler for a 4-issue VLIW core with mixed-latency functional units, covering hazard detection, register pressure, loop pipelining, and latency sensitivity.

You are building the scheduling pass of a compiler back end for a 4-issue VLIW processor. The machine has the following functional units and latencies:

  • Two ALU units, each with 1-cycle latency.
  • One load/store unit (LSU), fully pipelined, with 3-cycle latency for loads and 1-cycle effective latency for stores (a store writes no register).
  • One special-function unit (SFU) with 2-cycle latency.

Each cycle the processor can issue at most 4 operations, respecting the per-unit limits above. The hardware provides no interlocks; correctness is entirely the compiler's responsibility. Empty issue slots become NOPs.

You are given a basic block represented as a dependency DAG where each node is an instruction tagged with its functional unit and latency, and each edge carries a dependency type (RAW, WAR, WAW, or memory ordering).

Your tasks:

  1. Produce a legal instruction schedule that maximizes parallel issue and minimizes stall cycles. Show the cycle-by-cycle bundle layout.
  2. Explain how your scheduler detects and handles each hazard type (RAW, WAR, WAW, structural, memory aliasing, and control flow across blocks).
  3. Discuss how register pressure interacts with your scheduling decisions and what strategies you use to manage it.
  4. Suppose the basic block is the body of a tight loop. Describe how you would apply software pipelining, including the initiation interval, stage count, and register management.
  5. If the average load latency increases from 3 to 4 cycles, explain how your straight-line schedule and pipelined loop schedule change.

Hints

Hint 1

Model each dependency edge with its latency so a consumer can only issue once the producer's result is available; with no interlocks, the scheduler must insert explicit idle slots or fill them with independent work.

Hint 2

Use a priority function like latency-weighted critical-path height and greedily fill each cycle's unit slots in priority order; this is a heuristic since optimal scheduling is NP-hard.

Hint 3

Operate on SSA virtual registers before physical allocation to eliminate WAR and WAW false dependencies, then track live-register counts during scheduling to avoid spills.

Hint 4

For loops, compute the resource-constrained initiation interval (ResMII) from unit utilization and the recurrence-constrained interval (RecMII) from loop-carried dependencies, then use modulo scheduling.