-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Problem
Currently, all local variables are stored in stack slots. This can create unnecessary stack stores and loads even when a variable's address is never obtained
Proposed Solution
codegen should check to see if a variable is ever aliased with ^. This could probably be done in either the hir or hir_ty crates during lowering or type checking. Maybe when an Expr::Ref is created/parsed it would check to see if it's inner expression was a Variable before marking that variable as "aliased".
codegen would then check this flag (and Ty::is_aggregate) to know if it should allocate stack space for the variable or if it should instead use cranelift_frontend::Variable
Notes
Future optimizations could probably be made if it's known that a variable is never aliased. Structs could be split up into separate cranelift_frontend::Variables for their different fields. Although this would also need to check if a variable was passed as an argument.