[Mlir-commits] [llvm] [mlir] [openmp] [mlir][llvmir][OpenMP] Translate affinity clause in task construct to llvmir (PR #182223)
Tom Eccles
llvmlistbot at llvm.org
Wed Mar 11 04:00:11 PDT 2026
================
@@ -2229,6 +2224,78 @@ class TaskContextStructManager {
/// The type of the structure
llvm::Type *structTy = nullptr;
};
+
+/// IteratorInfo extracts and prepares loop bounds information from an
+/// mlir::omp::IteratorOp for lowering to LLVM IR.
+///
+/// It computes the per-dimension trip counts and the total linearized trip
+/// count, casted to i64. These are used to build a canonical loop and to
+/// reconstruct the physical induction variables inside the loop body.
+class IteratorInfo {
+private:
+ llvm::SmallVector<llvm::Value *> lowerBounds;
+ llvm::SmallVector<llvm::Value *> upperBounds;
+ llvm::SmallVector<llvm::Value *> steps;
+ llvm::SmallVector<llvm::Value *> trips;
+ unsigned dims;
+ llvm::Value *totalTrips;
+
+ llvm::Value *lookUpAsI64(mlir::Value val, const LLVM::ModuleTranslation &mt,
+ llvm::IRBuilderBase &builder) {
+ llvm::Value *v = mt.lookupValue(val);
+ if (!v)
+ return nullptr;
+ if (v->getType()->isIntegerTy(64))
+ return v;
+ if (v->getType()->isIntegerTy())
+ return builder.CreateSExtOrTrunc(v, builder.getInt64Ty());
+ return nullptr;
+ }
+
+public:
+ IteratorInfo(mlir::omp::IteratorOp itersOp,
+ mlir::LLVM::ModuleTranslation &moduleTranslation,
+ llvm::IRBuilderBase &builder) {
+ dims = itersOp.getLoopLowerBounds().size();
+ lowerBounds.resize(dims);
+ upperBounds.resize(dims);
+ steps.resize(dims);
+ trips.resize(dims);
+
+ for (unsigned d = 0; d < dims; ++d) {
+ llvm::Value *lb = lookUpAsI64(itersOp.getLoopLowerBounds()[d],
+ moduleTranslation, builder);
+ llvm::Value *ub = lookUpAsI64(itersOp.getLoopUpperBounds()[d],
+ moduleTranslation, builder);
+ llvm::Value *st =
+ lookUpAsI64(itersOp.getLoopSteps()[d], moduleTranslation, builder);
+ assert(lb && ub && st &&
+ "Expect lowerBounds, upperBounds, and steps in IteratorOp");
+
+ lowerBounds[d] = lb;
+ upperBounds[d] = ub;
+ steps[d] = st;
+
+ // trips = ((ub - lb) / step) + 1 (inclusive ub, assume positive step)
----------------
tblah wrote:
What guarantees the positive step? If this isn't in the operation verifier then this either needs handling here or we should at least generate an error message instead of producing incorrect code.
https://github.com/llvm/llvm-project/pull/182223
More information about the Mlir-commits
mailing list