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

Kaviya Rajendiran llvmlistbot at llvm.org
Tue Mar 4 23:00:18 PST 2025


================
@@ -5279,10 +5279,86 @@ OpenMPIRBuilder::getOpenMPDefaultSimdAlign(const Triple &TargetTriple,
   return 0;
 }
 
+static void appendNontemporalVars(BasicBlock *Block,
+                                  SmallVectorImpl<Value *> &NontemporalVars) {
+  for (Instruction &I : *Block) {
+    if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
+      if (CI->getIntrinsicID() == Intrinsic::memcpy) {
+        llvm::Value *DestPtr = CI->getArgOperand(0);
+        llvm::Value *SrcPtr = CI->getArgOperand(1);
+        for (const llvm::Value *Var : NontemporalVars) {
+          if (Var == SrcPtr) {
+            NontemporalVars.push_back(DestPtr);
+            break;
+          }
+        }
+      }
+    }
+  }
+}
+
+/** Attach nontemporal metadata to the load/store instructions of nontemporal
+ *  variables of \p 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
----------------
kaviya2510 wrote:

Hi @jsjodin,

Apologies for the delayed response. Yes, I think using a callback is helpful in this scenario. I have implemented the translation on the OpenMPToLLVMIRTranslation file and replaced the nontemporal function with callbacks in OMPIRBuilder.

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


More information about the Mlir-commits mailing list