mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
First steps towards using constant values in lowering. For now, we reuse the regular instruction lowering to lower constants. This mostly works, because we don't actually need an `llvm::Function` or a current basic block when lowering a constant most of the time. However, a special case is needed for lowering aggregate value constants because they would otherwise create a stack alloca to store the constant. Separate constant lowering code will be added in a future change to clean this up. When lowering a constant initializing expression, the result is a value of the destination type, rather than code to initialize the destination, so a separate copy step is required when finishing initialization from a constant for a type that uses in-place initialization. Handling this required extending `ReturnExpr` to track its destination location. We currently often create non-constant `*_access` SemIR instructions that are only used by constant `*_init` instructions. These cause lowering to leave behind `getelementptr` instructions in the lowered IR that are now unused. It should be possible to detect this case and avoid producing these instructions, or to produce them lazily, but for now we're just leaving them around for LLVM to clean up.