Now that we have a list of symbols to generate from the collector, we need to generate some sort of codegen IR. In this chapter, we will assume LLVM IR, since that's what rustc usually uses. The actual monomorphization is performed as we go, while we do the translation.
The code is split into modules which handle particular MIR primitives:
librustc_codegen_ssa::mir::blockwill deal with translating blocks and their terminators. The most complicated and also the most interesting thing this module does is generating code for function calls, including the necessary unwinding handling IR.
librustc_codegen_ssa::mir::statementtranslates MIR statements.
librustc_codegen_ssa::mir::operandtranslates MIR operands.
librustc_codegen_ssa::mir::placetranslates MIR place references.
librustc_codegen_ssa::mir::rvaluetranslates MIR r-values.
Before a function is translated a number of simple and primitive analysis
passes will run to help us generate simpler and more efficient LLVM IR. An
example of such an analysis pass would be figuring out which variables are
SSA-like, so that we can translate them to SSA directly rather than relying on
mem2reg for those variables. The analysis can be found in
Usually a single MIR basic block will map to a LLVM basic block, with very few
exceptions: intrinsic or function calls and less basic MIR statements like
assert can result in multiple basic blocks. This is a perfect lede into the
non-portable LLVM-specific part of the code generation. Intrinsic generation is
fairly easy to understand as it involves very few abstraction levels in between
and can be found in
TODO: discuss how constants are generated