[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 04:53:23 PST 2026


================
@@ -1870,9 +1821,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
     };
   }
 
-  OI->OuterAllocaBB = OuterAllocaBlock;
+  OI->OuterAllocBB = OuterAllocaBlock;
   OI->EntryBB = PRegEntryBB;
   OI->ExitBB = PRegExitBB;
+  OI->OuterDeallocBBs.reserve(OuterDeallocIPs.size());
+  for (InsertPointTy DeallocIP : OuterDeallocIPs)
+    OI->OuterDeallocBBs.push_back(DeallocIP.getBlock());
----------------
skatrak wrote:

I tried passing around and using `InsertionPoint`s for this, but that didn't work because they are generally created when the block itself has just been created and empty. The logic to deal with the addition of terminators and codegen in general doesn't update these `InsertPoint`s, so they ended up causing memory deallocations to be placed after basic block terminators.

Knowing that, and seeing that the `AllocaIP`s are used, and not just their block, I suppose the best course of action without over-complicating things too much would be to pass around allocation insert points and deallocation blocks, and always use the first insertion point of the block in the latter case.

I did also just `#include <llvm/IR/IRBuilder.h>` in CodeExtractor.h to simplify the argument list for the overrideable `CodeExtractor::allocateVar` and `CodeExtractor::deallocateVar`.

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


More information about the llvm-branch-commits mailing list