[Mlir-commits] [mlir] [mlir][acc] Add data clause deduplication pattern for kernel env (PR #231965)
Razvan Lupusoru
llvmlistbot at llvm.org
Wed Oct 14 10:57:57 PDT 2026
================
@@ -78,6 +78,87 @@ struct RemoveEmptyKernelEnvironment
}
};
+struct KernelEnvironmentDedupDataOperands
+ : public OpRewritePattern<acc::KernelEnvironmentOp> {
+ using OpRewritePattern<acc::KernelEnvironmentOp>::OpRewritePattern;
+
+ static bool isReductionDataOperand(Value operand) {
+ Operation *def = operand.getDefiningOp();
+ if (!def)
+ return false;
+ if (std::optional<DataClause> clause = getDataClause(def))
+ return *clause == DataClause::acc_reduction;
+ return false;
+ }
+
+ // Later clauses for one variable receive the same address, so the first
+ // remains. acc.map_info is a finalized mapping: its order and semantics
+ // stand. The variable alone does not identify it, since the flags and
+ // descriptors would have to be compared as well.
+ static bool isSameMappedVariable(Value lhs, Value rhs) {
+ if (lhs == rhs)
+ return true;
+ Operation *lhsDef = lhs.getDefiningOp();
+ Operation *rhsDef = rhs.getDefiningOp();
+ if (!lhsDef || !rhsDef || isa<MapInfoOp>(lhsDef) || isa<MapInfoOp>(rhsDef))
+ return false;
+ Value lhsVar = getVar(lhsDef);
+ return lhsVar && lhsVar == getVar(rhsDef) &&
+ getBounds(lhsDef) == getBounds(rhsDef);
+ }
----------------
razvanlupusoru wrote:
We do not care actually because subsequent clauses only increment present counter and provide existing mapping. However, it is important we do not change the order at this time because a create followed by a copyin is not the same as a copyin followed by create (that said, we may consider in future to make them equivalent and there is an open discussion about clause ordering from OpenACC spec perspective).
https://github.com/llvm/llvm-project/pull/231965
More information about the Mlir-commits
mailing list