[Mlir-commits] [llvm] [mlir] [MLIR][OpenMP] Lowering nontemporal clause to LLVM IR for SIMD directive (PR #118751)
Jan Leyonberg
llvmlistbot at llvm.org
Thu Feb 6 08:29:07 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
----------------
jsjodin wrote:
Can we create a callback for attaching metadata? Callbacks are usually how front end specific things are handled, unless it is something more generic and involved that the OpenMPIRBuilder has to keep track of.
https://github.com/llvm/llvm-project/pull/118751
More information about the Mlir-commits
mailing list