Skip to content

Commit

Permalink
[Utils] Finding ancestor in block (#913)
Browse files Browse the repository at this point in the history
Chipped off from review comment in
#904

#include changes: include the files that are used directly not
indirectly
  • Loading branch information
newling authored Nov 20, 2024
1 parent 96dfcc0 commit 0f4e8d2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "iree-amd-aie/Transforms/AMDAIEUtils.h"
#include "iree-amd-aie/Transforms/Passes.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Linalg/Transforms/Transforms.h"
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
#include "mlir/IR/Iterators.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@

#include "AMDAIEDmaUtils.h"

#include <cstdlib>

#include "AMDAIEUtils.h"
#include "iree-amd-aie/Transforms/AMDAIEUtils.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "mlir/Dialect/Utils/StaticValueUtils.h"

namespace mlir::iree_compiler::AMDAIE {

/// Return an ancestor of 'op' in 'block', or nullptr if no such ancestor.
Operation *getAncestorInBlock(Operation *op, Block *block) {
if (!op || !block) return nullptr;
auto parent = op;
while (parent && (parent->getBlock() != block))
parent = parent->getParentOp();
return parent;
}

bool areAccessPatternsCombinable(const SmallVector<OpFoldResult> &offsetsA,
const SmallVector<OpFoldResult> &sizesA,
const SmallVector<OpFoldResult> &stridesA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "iree-amd-aie/Transforms/AMDAIEUtils.h"
#include "iree-amd-aie/Transforms/Passes.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/SCF/Transforms/Transforms.h"
#include "mlir/IR/Iterators.h"
#include "mlir/Pass/Pass.h"

#define DEBUG_TYPE "iree-amdaie-peel-for-loop"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#include "AMDAIEUtils.h"

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
#include "mlir/Dialect/Linalg/Utils/Utils.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Iterators.h"

namespace mlir::iree_compiler::AMDAIE {

Expand Down Expand Up @@ -251,7 +251,7 @@ bool isMatmulInDefChain(Value operand) {
/// Utility to identify if `linalgOp` is an elementwise operation with a
/// matmul-like op upstream in its computation tree.
bool isMatmulProducerOfElementwise(linalg::LinalgOp linalgOp) {
if (!isElementwise(linalgOp) || isa<linalg::FillOp>(linalgOp)) {
if (!linalg::isElementwise(linalgOp) || isa<linalg::FillOp>(linalgOp)) {
return false;
}
// Check if any of the defining op is a matmul-like op.
Expand All @@ -272,6 +272,13 @@ std::string utohexstr(uint32_t value, size_t width, bool header,
return res + prefix + hexStr;
}

/// Return an ancestor of 'op' in 'block', or nullptr if no such ancestor.
Operation *getAncestorInBlock(Operation *op, Block *block) {
if (!op || !block) return nullptr;
while (op && (op->getBlock() != block)) op = op->getParentOp();
return op;
}

/// Find the largest factor of 'num' which is not larger than 'max'.
int detail::findLargestFactor(int num, int max) {
assert(max > 0 && "No factors less than or equal to 0 exist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
#ifndef IREE_AMD_AIE_TRANSFORMS_AMDAIEUTILS_H_
#define IREE_AMD_AIE_TRANSFORMS_AMDAIEUTILS_H_

#include <array>

#include "iree-amd-aie/IR/AMDAIEAttrs.h"
#include "iree/compiler/Dialect/HAL/IR/HALOps.h"
#include "mlir/Dialect/Linalg/Utils/Utils.h"
#include "iree-amd-aie/aie_runtime/AMDAIEEnums.h"
#include "iree/compiler/Dialect/HAL/IR/HALTypes.h"
#include "mlir/Dialect/Linalg/IR/LinalgInterfaces.h"
#include "mlir/IR/Types.h"

namespace mlir::iree_compiler::AMDAIE {
Expand Down Expand Up @@ -62,15 +60,22 @@ bool isMatmulProducerOfElementwise(linalg::LinalgOp linalgOp);
std::string utohexstr(uint32_t value, size_t width, bool header = true,
bool lowercase = false);

/// If `op` is in `block`, then return `op`. Otherwise traverse through parents
/// to the first ancestor of `op` that is in `block`, and return that
/// ancestor. If `op` has no ancestor in `block`, or if `op` is nullptr or
/// `block` is nullptr, return nullptr.
Operation *getAncestorInBlock(Operation *op, Block *block);

namespace detail {

// Returns the largest number that perfectly divides `num` that
// is less than or equal to max
/// Returns the largest number that perfectly divides `num` that
/// is less than or equal to max
int findLargestFactor(int num, int max);

// A variant where we prefer factors to also be a multiple of `multiple`
/// A variant where we prefer factors to also be a multiple of `multiple`
int findLargestFactor(int num, int max, int multiple);


} // namespace detail

} // namespace mlir::iree_compiler::AMDAIE
Expand Down

0 comments on commit 0f4e8d2

Please sign in to comment.