[clang] [CIR][OpenMP] Prevent HoistAllocas pass from hoisting above OpenMP regions (PR #206168)

Jan Leyonberg via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 29 12:01:45 PDT 2026


================
@@ -33,18 +34,34 @@ struct HoistAllocasPass : public impl::HoistAllocasBase<HoistAllocasPass> {
   void runOnOperation() override;
 };
 
+// Find the block that an alloca should be hoisted into. Allocas are normally
+// hoisted to the entry block of the enclosing function. However, an alloca may
+// be nested inside an OpenMP region such as omp.parallel, omp.teams
+// etc. Hoisting it out of these ops breaks the isolated from above requirement
+// for omp.teams and it changes privatization semantics.
+static mlir::Block *getHoistDestBlock(cir::AllocaOp alloca) {
+  mlir::Region *region = alloca->getParentRegion();
+  while (true) {
+    mlir::Operation *parentOp = region->getParentOp();
+    if (mlir::isa<cir::FuncOp>(parentOp) ||
+        mlir::isa<mlir::omp::OutlineableOpenMPOpInterface>(parentOp))
----------------
jsjodin wrote:

@xlauko did you have any more feedback on this?

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


More information about the cfe-commits mailing list