Blender
V3.3
|
Functions | |
void | move_destructs_up (MFProcedure &procedure, MFInstruction &block_end_instr) |
void blender::fn::procedure_optimization::move_destructs_up | ( | MFProcedure & | procedure, |
MFInstruction & | block_end_instr | ||
) |
When generating a procedure, destruct instructions (#MFDestructInstruction) have to be inserted for all variables that are not outputs. Often the simplest approach is to add these instructions at the very end. However, when the procedure is executed this is not optimal, because many more variables are initialized at the same time than necessary. This inhibits the reuse of memory buffers which decreases performance and increases memory use.
This optimization pass moves destruct instructions up in the procedure. The goal is to destruct each variable right after its last use.
For simplicity, and because this is the most common use case, this optimization currently only works on a single chain of instructions. Destruct instructions are not moved across branches.
procedure | The procedure that should be optimized. |
block_end_instr | The instruction that points to the last instruction within a linear chain of instructions. The algorithm moves instructions backward starting at this instruction. |
Definition at line 7 of file multi_function_procedure_optimization.cc.
References blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::fn::Call, blender::fn::Destruct, blender::fn::MFInstructionCursor::instruction(), blender::fn::MFCallInstruction::next(), blender::fn::MFDestructInstruction::next(), blender::fn::MFCallInstruction::params(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::pop_default(), blender::fn::MFInstruction::prev(), blender::fn::MFCallInstruction::set_next(), blender::fn::MFDestructInstruction::set_next(), blender::fn::MFInstructionCursor::set_next(), blender::Span< T >::size(), blender::fn::MFInstruction::type(), and blender::fn::MFDestructInstruction::variable().
Referenced by blender::fn::build_multi_function_procedure_for_fields().