Master the fundamental concepts of intermediate representation through this focused micro-challenge.
A control flow graph has basic blocks as nodes and jumps as edges. LLVM's BasicBlock, GCC's edge lists, and every dataflow analysis start here. Building the CFG from IR means partitioning instructions at leaders and wiring fall-through and branch targets.
Leaders: first instruction, targets of jumps, instructions after branches. Each leader starts a basic block. Successors: fall-through to next block, branch targets. Predecessors are the inverse edges.
cLoading…
Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will build a control flow graph from your IR. This exercise requires identifying basic block boundaries, creating block nodes, and linking predecessors and successors for each branch and fall-through.
Build a Control Flow Graph from three-address code.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github