[Mlir-commits] [mlir] [mlir][linalg] Add more precise memory effects to linalg op (PR #92079)
Matthias Springer
llvmlistbot at llvm.org
Tue May 14 04:54:35 PDT 2024
================
@@ -1122,29 +1122,38 @@ ParseResult GenericOp::parse(OpAsmParser &parser, OperationState &result) {
static void getGenericEffectsImpl(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects,
- ValueRange results, const ValueRange inputOperands,
- ValueRange outputOperands) {
- for (auto operand : inputOperands) {
+ LinalgOp linalgOp) {
+ ValueRange inputOperands = linalgOp.getDpsInputs();
+ for (auto [index, operand] : llvm::enumerate(inputOperands)) {
if (!llvm::isa<MemRefType>(operand.getType()))
continue;
- effects.emplace_back(MemoryEffects::Read::get(), operand,
- SideEffects::DefaultResource::get());
+ if (linalgOp.payloadUsesValueFromOperand(&linalgOp->getOpOperand(index))) {
+ effects.emplace_back(MemoryEffects::Read::get(), operand, 0, true,
+ SideEffects::DefaultResource::get());
+ }
}
- for (auto operand : outputOperands) {
+ unsigned inputOperandSize = inputOperands.size();
+ unsigned usedOutputSize =
+ linalgOp.getOpOperandsMatchingBBargs().size() - inputOperandSize;
+
+ for (auto [index, operand] : llvm::enumerate(linalgOp.getDpsInits())) {
if (!llvm::isa<MemRefType>(operand.getType()))
continue;
- effects.emplace_back(MemoryEffects::Read::get(), operand,
- SideEffects::DefaultResource::get());
- effects.emplace_back(MemoryEffects::Write::get(), operand,
+ if (index < usedOutputSize &&
----------------
matthias-springer wrote:
Why is this needed? `payloadUsesValueFromOperand` should be sufficient. Are you seeing a crash/out-of-bounds access in `getMatchingBlockArgument` without this change? In that case we should update `getMatchingBlockArgument` such that it returns a "null" BlockArgument. And `payloadUsesValueFromOperand` should return `false` is such a case.
https://github.com/llvm/llvm-project/pull/92079
More information about the Mlir-commits
mailing list