//===- DecomposeAffineOps.cpp - Decompose affine ops into finer-grained ---===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements functionality to progressively decompose coarse-grained // affine ops into finer-grained ops. // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Transforms/Transforms.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/Support/Debug.h" usingnamespacemlir; usingnamespacemlir::affine; #define DEBUG_TYPE … #define DBGS() … #define DBGSNL() … /// Count the number of loops surrounding `operand` such that operand could be /// hoisted above. /// Stop counting at the first loop over which the operand cannot be hoisted. static int64_t numEnclosingInvariantLoops(OpOperand &operand) { … } void mlir::affine::reorderOperandsByHoistability(RewriterBase &rewriter, AffineApplyOp op) { … } /// Build an affine.apply that is a subexpression `expr` of `originalOp`s affine /// map and with the same operands. /// Canonicalize the map and operands to deduplicate and drop dead operands /// before returning but do not perform maximal composition of AffineApplyOp /// which would defeat the purpose. static AffineApplyOp createSubApply(RewriterBase &rewriter, AffineApplyOp originalOp, AffineExpr expr) { … } FailureOr<AffineApplyOp> mlir::affine::decompose(RewriterBase &rewriter, AffineApplyOp op) { … }