Skip to content

Commit bfe8523

Browse files
authored
[mlir][IntegerRangeAnalysis] expose maybeReplaceWithConstant (#133151)
This PR exposes `maybeReplaceWithConstant` in headers for downstream use.
1 parent fc0102e commit bfe8523

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "mlir/Interfaces/InferIntRangeInterface.h"
2323

2424
namespace mlir {
25+
class RewriterBase;
2526
namespace dataflow {
2627

2728
/// This lattice element represents the integer value range of an SSA value.
@@ -83,6 +84,9 @@ LogicalResult staticallyNonNegative(DataFlowSolver &solver, Operation *op);
8384
/// to use a non-64-bit index.
8485
LogicalResult staticallyNonNegative(DataFlowSolver &solver, Value v);
8586

87+
LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
88+
RewriterBase &rewriter, Value value);
89+
8690
} // end namespace dataflow
8791
} // end namespace mlir
8892

mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ static void copyIntegerRange(DataFlowSolver &solver, Value oldVal,
5757
*oldState);
5858
}
5959

60+
namespace mlir::dataflow {
6061
/// Patterned after SCCP
61-
static LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
62-
PatternRewriter &rewriter,
63-
Value value) {
62+
LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
63+
RewriterBase &rewriter, Value value) {
6464
if (value.use_empty())
6565
return failure();
6666
std::optional<APInt> maybeConstValue = getMaybeConstantValue(solver, value);
@@ -95,6 +95,7 @@ static LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
9595
rewriter.replaceAllUsesWith(value, constOp->getResult(0));
9696
return success();
9797
}
98+
} // namespace mlir::dataflow
9899

99100
namespace {
100101
class DataFlowListener : public RewriterBase::Listener {

0 commit comments

Comments
 (0)