[llvm-branch-commits] [mlir] [mlir][OpenMP] Pack task private variables into a heap-allocated context struct (PR #125307)
Tom Eccles via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 5 01:46:21 PST 2025
================
@@ -1730,6 +1730,126 @@ buildDependData(std::optional<ArrayAttr> dependKinds, OperandRange dependVars,
}
}
+static bool privatizerReadsSourceVariable(omp::PrivateClauseOp &priv) {
+ if (priv.getDataSharingType() == omp::DataSharingClauseType::FirstPrivate)
+ return true;
+
+ Region &initRegion = priv.getInitRegion();
+ if (initRegion.empty())
+ return false;
+
+ BlockArgument sourceVariable = priv.getInitMoldArg();
+ if (!sourceVariable)
+ return false;
+ return !sourceVariable.use_empty();
+}
+
+namespace {
+/// TaskContextStructManager takes care of creating and freeing a structure
+/// containing information needed by the task body to execute.
+class TaskContextStructManager {
+public:
+ TaskContextStructManager(llvm::IRBuilderBase &builder,
+ LLVM::ModuleTranslation &moduleTranslation,
+ MutableArrayRef<omp::PrivateClauseOp> privateDecls)
+ : builder{builder}, moduleTranslation{moduleTranslation},
+ privateDecls{privateDecls} {}
+
+ /// Creates a heap allocated struct containing space for each private
+ /// variable. Returns nullptr if there are is no struct needed. Invariant:
+ /// privateVarTypes, privateDecls, and the elements of the structure should
+ /// all have the same order (although privateDecls which do not read from the
+ /// mold argument are skipped).
+ void generateTaskContextStruct();
+
+ /// Create GEPs to access each member of the structure representing a private
+ /// variable, adding them to llvmPrivateVars. Null values are added where
+ /// private decls were skipped so that the ordering continues to match the
+ /// private decls.
+ void createGEPsToPrivateVars(SmallVectorImpl<llvm::Value *> &llvmPrivateVars);
+
+ /// De-allocate the task context structure.
+ void freeStructPtr();
+
+ llvm::Value *getStructPtr() { return structPtr; }
+
+private:
+ llvm::IRBuilderBase &builder;
+ LLVM::ModuleTranslation &moduleTranslation;
+ MutableArrayRef<omp::PrivateClauseOp> privateDecls;
----------------
tblah wrote:
I agree it should be, but unfortunately the table-gen accessors (e.g. `getRegions()`, `getCopyRegion()`) for the mlir operation aren't marked `const`. This makes sense because the region can be mutated through this reference, but it is a shame there aren't any `const` alternatives.
The non-const regions means that `getInitMoldArg()` etc cannot be `const`.
https://github.com/llvm/llvm-project/pull/125307
More information about the llvm-branch-commits
mailing list