Master the fundamental concepts of optimizations through this focused micro-challenge.
Basic blocks are straight-line code with single entry and exit. Analyses partition the CFG into blocks, then compute properties per block: predecessors, successors, dominators, loop membership. LLVM's LoopInfo and GCC's loop passes depend on this foundation.
For each block: list of instructions, predecessor and successor sets, whether it is a loop header, whether it dominates its successors' join nodes.
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 implement basic block analysis on your CFG. This exercise requires identifying blocks, computing predecessor and successor lists, and preparing data structures for loop and dominance analyses.
Implement basic block identification and control flow graph construction.
Implement leader detection:
Build basic blocks:
Construct CFG:
Implement CFG utilities:
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