[Mlir-commits] [llvm] [mlir] [MLIR][OpenMP] Lowering nontemporal clause to LLVM IR for SIMD directive (PR #118751)

Kaviya Rajendiran llvmlistbot at llvm.org
Wed Mar 12 01:51:27 PDT 2025


================
@@ -2527,6 +2541,72 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
 
   llvm::MapVector<llvm::Value *, llvm::Value *> alignedVars;
   llvm::omp::OrderKind order = convertOrderKind(simdOp.getOrder());
+
+  llvm::SmallVector<llvm::Value *> nontemporalOrigVars;
+  mlir::OperandRange nontemporals = simdOp.getNontemporalVars();
+  for (mlir::Value nontemporal : nontemporals) {
+    llvm::Value *nt = moduleTranslation.lookupValue(nontemporal);
+    nontemporalOrigVars.push_back(nt);
+  }
+
+  /** Call back function to attach nontemporal metadata to the load/store
+   * instructions of nontemporal variables of Block.
+   * Nontemporal variables may be a scalar, fixed size or allocatable
+   * or pointer array
+   *
+   * Example scenarios for nontemporal variables:
+   * Case 1: Scalar variable
+   *    If the nontemporal variable is a scalar, it is allocated on stack.Load
+   * and store instructions directly access the alloca pointer of the scalar
+   * variable for fetching information about scalar variable or  writing
+   * into the scalar variable. Mark those load and store instructions as
+   * non-temporal.
+   *
+   * Case 2: Fixed Size array
+   *    If the nontemporal variable is a fixed-size array, it is allocated
+   * as a contiguous block of memory. It uses one GEP instruction, to compute
+   * the address of each individual array elements and perform load or store
+   * operation on it. Mark those load and store instructions as non-temporal.
+   *
+   * Case 3: Allocatable array
+   *     For an allocatable array, which might involve runtime type descriptor,
+   * needs to navigate through descriptors using two or more GEP and load
+   * instructions to compute the address of each individual element in an array.
+   * Mark those load or store which access the individual array elements as
+   * non-temporal.
+   */
----------------
kaviya2510 wrote:

Thanks for the comments.
Yes, all the three cases are still applicable. I moved the entire implementation from OpenMPIRBuilder to OpenMPToLLVMIRTranslation.cpp and made this changes specific to flang.

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


More information about the Mlir-commits mailing list