Intercepting lowering of stack adjustments

For a long time we have had code for custom lowering of adjustments to the stack pointer. But until recently we did not realise that we were handling only places that provided a fixed-value for such adjustments, and the ISD nodes ‘ADJCALLSTACKDOWN’ and ‘ADJCALLSTACKUP’ are only described in our TableGen descriptions for immediates. This hasn’t previous mattered as LLVM produces valid instruction sequences for variable adjustments anyway using an intermediate register.

However, we have a recent requirement to also perform custom handling of stack adjustments for non-immediate values, for instance those that reserve stack for VLAs and ‘alloca’. I would like to be able to intercept lowering for these where a computed value is used, and to be able to differentiate between when stack is being reserved and when it is being released.

Where should I best handle this? All of the targets that use the ‘ADJCALLSTACK’ nodes appear to do so only for immediate values, so I haven’t been able to learn by example.

Thanks,

MartinO

If I’m not mistaken, try grepping for DYNALLOC; that should point you to how a number of targets implement allocas.

—escha

Thanks. that looks really promising! I hadn’t spotted that ISD node before.

All the best,

MartinO