28 .Case<linalg::FillOp, linalg::CopyOp>([&](
auto op) {
29 return op && op.getInputs().size() == 1 &&
32 .Default([&](
auto) {
return false; });
61 if (!addOp.hasPureTensorSemantics())
64 Value dominatingOperand =
nullptr;
65 linalg::LinalgOp dominatedOp =
nullptr;
67 Value lhs = addOp.getInputs()[0];
68 Value rhs = addOp.getInputs()[1];
77 dominatingOperand = lhs;
84 dominatingOperand = rhs;
88 if (!dominatingOperand || !dominatedOp)
98 auto dominatedDestOp =
99 dyn_cast<DestinationStyleOpInterface>((
Operation *)dominatedOp);
100 if (dominatedOp->getNumResults() != 1 ||
102 (!dominatedDestOp || dominatedDestOp.getNumDpsInits() != 1))
104 dominatedOp,
"expected dominated op to be single-result "
105 "destination-passing contraction");
108 if (!dominatedOp->getResult(0).hasOneUse())
111 "expected linalg.add to be single user of contraction's result");
115 auto *destOperand = dominatedDestOp.getDpsInitOperand(0);
118 dominatedOp,
"expected dominated op's dest to be additive zero");
128 for (
auto expr : indexMaps[destOperand->getOperandNumber()].getResults()) {
129 auto dim = dyn_cast<AffineDimExpr>(expr);
130 if (!dim || prevDimPos >
static_cast<int>(dim.getPosition()))
132 dominatedOp,
"expected index_map for contraction's dest to be an "
133 "ordered projection");
134 prevDimPos = dim.getPosition();
141 dominatedOp, [&]() { dominatedOp->setOperand(2, dominatingOperand); });
static bool isDefinedAsZero(Value val)
A class for computing basic dominance information.
bool properlyDominates(Operation *a, Operation *b, bool enclosingOpOk=true) const
Return true if operation A properly dominates operation B, i.e.
Operation is the basic unit of execution within MLIR.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
void modifyOpInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around an in-place modification of an operation.
void replaceAllOpUsesWith(Operation *from, ValueRange to)
Find uses of from and replace them with to.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
bool isaContractionOpInterface(LinalgOp linalgOp)
Checks whether linalgOp conforms to ContractionOpInterface.
void populateFoldAddIntoDestPatterns(RewritePatternSet &patterns)
Pattern to replace linalg.add when destination passing on a contraction op suffices for achieving the...
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
detail::constant_int_predicate_matcher m_Zero()
Matches a constant scalar / vector splat / tensor splat integer zero.
const FrozenRewritePatternSet & patterns
detail::constant_float_predicate_matcher m_AnyZeroFloat()
Matches a constant scalar / vector splat / tensor splat float (both positive and negative) zero.
Replace a linalg.add with one operand the single user of a contraction, which has a zero-filled,...
LogicalResult matchAndRewrite(linalg::AddOp addOp, PatternRewriter &rewriter) const override
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...