[llvm-branch-commits] [clang] [CIR][OpenMP] Add support for host_eval so that SPMD kernels can be used (PR #229259)

Erich Keane via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 2 11:50:15 PST 2026


================
@@ -325,13 +415,22 @@ emitOMPWorksharingLoop(CIRGenFunction &cgf, const OMPLoopDirective &s,
         vd, addPrivateCounter(cgf, cgm, loc, privateVd, clauseOps));
   }
 
-  mlir::Value tripCountCir = cgf.emitScalarExpr(s.getNumIterations());
-  auto cirIntType = mlir::cast<cir::IntType>(tripCountCir.getType());
-  mlir::Value zero = builder.createBuiltinIntCast(
-      loc, builder.getConstInt(loc, cirIntType, 0));
-  mlir::Value one = builder.createBuiltinIntCast(
-      loc, builder.getConstInt(loc, cirIntType, 1));
-  mlir::Value tripCount = builder.createBuiltinIntCast(loc, tripCountCir);
+  mlir::Value zero, tripCount, one;
+  if (consumingHostEval) {
+    // Consume the host_eval bounds forwarded by the enclosing omp.target.
+    cgf.ompHostEvalBounds->applied = true;
+    zero = cgf.ompHostEvalBounds->zero;
+    tripCount = cgf.ompHostEvalBounds->tripCount;
+    one = cgf.ompHostEvalBounds->one;
+  } else {
+    mlir::Value tripCountCir = cgf.emitScalarExpr(s.getNumIterations());
+    auto cirIntType = mlir::cast<cir::IntType>(tripCountCir.getType());
----------------
erichkeane wrote:

without removing the 0/1 here, it seems awkward to have this all re-created here.  Disregard if we're only calculating the trip-count, but we should probably split this into a function otherwise (maybe the ompHostEvalBounds function of some sort?).

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


More information about the llvm-branch-commits mailing list