[Mlir-commits] [mlir] [mlir][acc] Add LegalizeDataValues support for DeclareEnterOp (PR #138008)
Razvan Lupusoru
llvmlistbot at llvm.org
Wed Apr 30 12:42:09 PDT 2025
================
@@ -71,7 +72,54 @@ static void replaceAllUsesInAccComputeRegionsWith(Value orig, Value replacement,
}
template <typename Op>
-static void collectAndReplaceInRegion(Op &op, bool hostToDevice) {
+static void replaceAllUsesInUnstructuredComputeRegionWith(
+ Op &op, llvm::SmallVector<std::pair<Value, Value>> &values,
+ DominanceInfo &domInfo, PostDominanceInfo &postDomInfo) {
+
+ Operation *exitOp = op.getOperation();
+ if constexpr (std::is_same_v<Op, acc::DeclareEnterOp>) {
+ // For declare enter/exit pairs, verify there is exactly one exit op using
+ // the token
+ if (!op.getToken().hasOneUse())
+ op.emitError("declare enter token must have exactly one use");
+ Operation *user = *op.getToken().getUsers().begin();
+ auto declareExit = dyn_cast<acc::DeclareExitOp>(user);
+ if (!declareExit)
+ op.emitError("declare enter token must be used by declare exit op");
+ exitOp = declareExit;
+ } else if constexpr (std::is_same_v<Op, acc::EnterDataOp>) {
----------------
razvanlupusoru wrote:
I am excited about the potential to support acc.enter_data. As I looked at your algorithm here though I realized that maybe it should be left for another change. This is because enter_data and exit_data don't come in pairs - so a bit more analysis is needed to get this right. More specifically, finding an exit_data does not constitute the end of the lifetime for a particular variable.
https://github.com/llvm/llvm-project/pull/138008
More information about the Mlir-commits
mailing list