[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Add support for explicit deallocation points (PR #154752)

Sergio Afonso via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 23 05:40:03 PST 2026


skatrak wrote:

Thanks @tblah for your comments (and your patience, it's taken me a long time to get back to this!).

> As I understand it, it is best to create all allocas together because then it can all be reduced to a single addition/subtraction on the stack pointer instead of a series of them. Putting executable code (e.g. calls to heap allocators) might lead to there being several separate adjustments to the stack pointer. Also as I understand it, collecting allocas together (ideally at the start of the entry block, after we have done all of the outlining) is considered a more canonical form of LLVMIR (it is better than it used to be but we definitely don't achieve this in all cases currently).

My understanding of the current behavior is that static allocas are those with a constant size and placed in a function's entry block[^1], regardless of other instructions. Stack objects are later created for them[^2], and those are the ones used to determine the total stack size and what the offset into it corresponds to each alloca.

If I understood that correctly, then it doesn't matter whether there are interleaved function calls. What does seem to matter is whether we put allocas in the entry block vs elsewhere, which I think we're not currently very good at in Flang. But we do need to keep in mind, when we try to improve alloca placement, that device shared memory allocations are not intended to go into the entry block in the same way, so at some point we might have to use separate insert points for both eventually.

[^1]: https://github.com/llvm/llvm-project/blob/eac18e783f034bd294a82cd0e69a7abf73583d28/llvm/lib/IR/Instructions.cpp#L1300
[^2]: https://github.com/llvm/llvm-project/blob/eac18e783f034bd294a82cd0e69a7abf73583d28/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp#L142

https://github.com/llvm/llvm-project/pull/154752


More information about the llvm-branch-commits mailing list