llvmllvm-irssa

Do PHI nodes remain in LLVM IR until compilation to binary?


I am new to LLVM and Intermediate Representation (IR), and I am trying to understand how PHI nodes are handled in LLVM IR. I understand that PHI nodes are a fundamental component of SSA (Static Single Assignment) form in LLVM IR, and are used to represent control flow in a program.

However, I am not sure if PHI nodes remain in LLVM IR until compilation to binary. Are all optimizations in LLVM's optimization pipeline designed to work with PHI nodes and SSA form, or are there cases where PHI nodes need to be eliminated or modified before optimization can take place?

I would appreciate any insights or clarifications on this topic. Thank you!


Solution

  • LLVM compilation pipeline consists of dozens of separate transformations (called passes) which can roughly be split to several main phases:

    As you can see, the last three phases do not use SSA (they use copies instead of PHI instructions).