[Mlir-commits] [mlir] bfe8523 - [mlir][IntegerRangeAnalysis] expose maybeReplaceWithConstant (#133151)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Mar 26 15:10:15 PDT 2025


Author: Maksim Levental
Date: 2025-03-26T18:10:12-04:00
New Revision: bfe85230e2dc27493b82ffba5a46c8f7449a6e10

URL: https://github.com/llvm/llvm-project/commit/bfe85230e2dc27493b82ffba5a46c8f7449a6e10
DIFF: https://github.com/llvm/llvm-project/commit/bfe85230e2dc27493b82ffba5a46c8f7449a6e10.diff

LOG: [mlir][IntegerRangeAnalysis] expose maybeReplaceWithConstant (#133151)

This PR exposes `maybeReplaceWithConstant` in headers for downstream
use.

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
    mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
index b9e5573d6ad40..72ec6061cbb62 100644
--- a/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
@@ -22,6 +22,7 @@
 #include "mlir/Interfaces/InferIntRangeInterface.h"
 
 namespace mlir {
+class RewriterBase;
 namespace dataflow {
 
 /// This lattice element represents the integer value range of an SSA value.
@@ -83,6 +84,9 @@ LogicalResult staticallyNonNegative(DataFlowSolver &solver, Operation *op);
 /// to use a non-64-bit index.
 LogicalResult staticallyNonNegative(DataFlowSolver &solver, Value v);
 
+LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
+                                       RewriterBase &rewriter, Value value);
+
 } // end namespace dataflow
 } // end namespace mlir
 

diff  --git a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
index f866c91ef6e39..1cb9453ccf3c9 100644
--- a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
@@ -57,10 +57,10 @@ static void copyIntegerRange(DataFlowSolver &solver, Value oldVal,
       *oldState);
 }
 
+namespace mlir::dataflow {
 /// Patterned after SCCP
-static LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
-                                              PatternRewriter &rewriter,
-                                              Value value) {
+LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
+                                       RewriterBase &rewriter, Value value) {
   if (value.use_empty())
     return failure();
   std::optional<APInt> maybeConstValue = getMaybeConstantValue(solver, value);
@@ -95,6 +95,7 @@ static LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
   rewriter.replaceAllUsesWith(value, constOp->getResult(0));
   return success();
 }
+} // namespace mlir::dataflow
 
 namespace {
 class DataFlowListener : public RewriterBase::Listener {


        


More information about the Mlir-commits mailing list