[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:16 PST 2026
================
@@ -284,6 +347,28 @@ static Address addPrivateCounter(CIRGenFunction &cgf, CIRGenModule &cgm,
return moldAddr;
}
+/// Computes a target SPMD loop's normalized `[0, tripCount)` bounds at the
+/// host insertion point, as builtin-integer values for the enclosing
+/// omp.target's host_eval operands. All three are forwarded even though
+/// only the trip count is runtime-dependent, since the dialect requires an
+/// SPMD loop_nest's bounds to be host-evaluated in full.
+static std::optional<CIRGenFunction::OMPHostEvalBounds>
+emitHostEvalLoopBounds(CIRGenFunction &cgf, const OMPLoopDirective &s) {
+ if (emitPreinits(cgf, s.getPreInits()).failed())
+ return std::nullopt;
+ CIRGenBuilderTy &builder = cgf.getBuilder();
+ mlir::Location loc = cgf.getLoc(s.getBeginLoc());
+ mlir::Value tripCountCir = cgf.emitScalarExpr(s.getNumIterations());
+ auto cirIntType = mlir::cast<cir::IntType>(tripCountCir.getType());
+ CIRGenFunction::OMPHostEvalBounds hev;
+ hev.zero = builder.createBuiltinIntCast(
+ loc, builder.getConstInt(loc, cirIntType, 0));
+ hev.tripCount = builder.createBuiltinIntCast(loc, tripCountCir);
+ hev.one = builder.createBuiltinIntCast(
----------------
erichkeane wrote:
Yeah, the zero/1 + a cast is a little weird? Could we possibly just create this every time we need to refer to it? Or are we expecting these to be modified in a way that the IR needs them?
https://github.com/llvm/llvm-project/pull/229259
More information about the llvm-branch-commits
mailing list