Skip to content

[MLIR] Fix dangling llvm::function_ref references #114950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct BufferResultsToOutParamsOpts {

// Filter function; returns true if the function should be converted.
// Defaults to true, i.e. all functions are converted.
llvm::function_ref<bool(func::FuncOp *)> filterFn = [](func::FuncOp *func) {
std::function<bool(func::FuncOp *)> filterFn = [](func::FuncOp *func) {
return true;
};

Expand Down
11 changes: 5 additions & 6 deletions mlir/lib/Dialect/SCF/IR/SCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,13 +1084,12 @@ struct ForOpTensorCastFolder : public OpRewritePattern<ForOp> {
continue;

// Create a new ForOp with that iter operand replaced.
ValueTypeCastFnTy castFn = [](OpBuilder &b, Location loc, Type type,
Value source) {
return b.create<tensor::CastOp>(loc, type, source);
};
rewriter.replaceOp(
op, replaceAndCastForOpIterArg(rewriter, op, iterOpOperand,
incomingCast.getSource(), castFn));
op, replaceAndCastForOpIterArg(
rewriter, op, iterOpOperand, incomingCast.getSource(),
[](OpBuilder &b, Location loc, Type type, Value source) {
return b.create<tensor::CastOp>(loc, type, source);
}));
return success();
}
return failure();
Expand Down
21 changes: 8 additions & 13 deletions mlir/lib/Interfaces/Utils/InferIntRangeCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ ConstantIntRanges
mlir::intrange::inferCeilDivU(ArrayRef<ConstantIntRanges> argRanges) {
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];

DivisionFixupFn ceilDivUIFix =
[](const APInt &lhs, const APInt &rhs,
const APInt &result) -> std::optional<APInt> {
auto ceilDivUIFix = [](const APInt &lhs, const APInt &rhs,
const APInt &result) -> std::optional<APInt> {
if (!lhs.urem(rhs).isZero()) {
bool overflowed = false;
APInt corrected =
Expand Down Expand Up @@ -368,9 +367,8 @@ ConstantIntRanges
mlir::intrange::inferCeilDivS(ArrayRef<ConstantIntRanges> argRanges) {
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];

DivisionFixupFn ceilDivSIFix =
[](const APInt &lhs, const APInt &rhs,
const APInt &result) -> std::optional<APInt> {
auto ceilDivSIFix = [](const APInt &lhs, const APInt &rhs,
const APInt &result) -> std::optional<APInt> {
if (!lhs.srem(rhs).isZero() && lhs.isNonNegative() == rhs.isNonNegative()) {
bool overflowed = false;
APInt corrected =
Expand All @@ -386,9 +384,8 @@ ConstantIntRanges
mlir::intrange::inferFloorDivS(ArrayRef<ConstantIntRanges> argRanges) {
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];

DivisionFixupFn floorDivSIFix =
[](const APInt &lhs, const APInt &rhs,
const APInt &result) -> std::optional<APInt> {
auto floorDivSIFix = [](const APInt &lhs, const APInt &rhs,
const APInt &result) -> std::optional<APInt> {
if (!lhs.srem(rhs).isZero() && lhs.isNonNegative() != rhs.isNonNegative()) {
bool overflowed = false;
APInt corrected =
Expand Down Expand Up @@ -603,8 +600,7 @@ ConstantIntRanges
mlir::intrange::inferShrS(ArrayRef<ConstantIntRanges> argRanges) {
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];

ConstArithFn ashr = [](const APInt &l,
const APInt &r) -> std::optional<APInt> {
auto ashr = [](const APInt &l, const APInt &r) -> std::optional<APInt> {
return r.uge(r.getBitWidth()) ? std::optional<APInt>() : l.ashr(r);
};

Expand All @@ -616,8 +612,7 @@ ConstantIntRanges
mlir::intrange::inferShrU(ArrayRef<ConstantIntRanges> argRanges) {
const ConstantIntRanges &lhs = argRanges[0], &rhs = argRanges[1];

ConstArithFn lshr = [](const APInt &l,
const APInt &r) -> std::optional<APInt> {
auto lshr = [](const APInt &l, const APInt &r) -> std::optional<APInt> {
return r.uge(r.getBitWidth()) ? std::optional<APInt>() : l.lshr(r);
};
return minMaxBy(lshr, {lhs.umin(), lhs.umax()}, {rhs.umin(), rhs.umax()},
Expand Down
Loading