19 #define GEN_PASS_DEF_ARITHINTRANGEOPTS
20 #include "mlir/Dialect/Arith/Transforms/Passes.h.inc"
35 if (!
intersects(std::move(lhs), std::move(rhs)))
42 if (!
intersects(std::move(lhs), std::move(rhs)))
69 return handleSlt(std::move(rhs), std::move(lhs));
73 return handleSle(std::move(rhs), std::move(lhs));
97 return handleUlt(std::move(rhs), std::move(lhs));
101 return handleUle(std::move(rhs), std::move(lhs));
114 if (!lhsResult || lhsResult->getValue().isUninitialized())
119 if (!rhsResult || rhsResult->getValue().isUninitialized())
124 std::array<HandlerFunc, arith::getMaxEnumValForCmpIPredicate() + 1>
126 using Pred = arith::CmpIPredicate;
127 handlers[
static_cast<size_t>(Pred::eq)] = &
handleEq;
128 handlers[
static_cast<size_t>(Pred::ne)] = &
handleNe;
129 handlers[
static_cast<size_t>(Pred::slt)] = &
handleSlt;
130 handlers[
static_cast<size_t>(Pred::sle)] = &
handleSle;
131 handlers[
static_cast<size_t>(Pred::sgt)] = &
handleSgt;
132 handlers[
static_cast<size_t>(Pred::sge)] = &
handleSge;
133 handlers[
static_cast<size_t>(Pred::ult)] = &
handleUlt;
134 handlers[
static_cast<size_t>(Pred::ule)] = &
handleUle;
135 handlers[
static_cast<size_t>(Pred::ugt)] = &
handleUgt;
136 handlers[
static_cast<size_t>(Pred::uge)] = &
handleUge;
138 HandlerFunc handler = handlers[
static_cast<size_t>(op.getPredicate())];
150 op,
static_cast<int64_t
>(*result), 1);
158 struct IntRangeOptimizationsPass
159 :
public arith::impl::ArithIntRangeOptsBase<IntRangeOptimizationsPass> {
161 void runOnOperation()
override {
168 return signalPassFailure();
185 return std::make_unique<IntRangeOptimizationsPass>();
static FailureOr< bool > handleUlt(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleSlt(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleUgt(ConstantIntRanges lhs, ConstantIntRanges rhs)
static bool intersects(const ConstantIntRanges &lhs, const ConstantIntRanges &rhs)
Returns true if 2 integer ranges have intersection.
static FailureOr< bool > handleUge(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleSge(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleUle(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleNe(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleSgt(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleEq(ConstantIntRanges lhs, ConstantIntRanges rhs)
static FailureOr< bool > handleSle(ConstantIntRanges lhs, ConstantIntRanges rhs)
A set of arbitrary-precision integers representing bounds on a given integer value.
const APInt & smax() const
The maximum value of an integer when it is interpreted as signed.
const APInt & smin() const
The minimum value of an integer when it is interpreted as signed.
const APInt & umax() const
The maximum value of an integer when it is interpreted as unsigned.
const APInt & umin() const
The minimum value of an integer when it is interpreted as unsigned.
The general data-flow analysis solver.
AnalysisT * load(Args &&...args)
Load an analysis into the solver. Return the analysis instance.
LogicalResult initializeAndRun(Operation *top)
Initialize the children analyses starting from the provided top-level operation and run the analysis ...
This class provides support for representing a failure result, or a valid value of type T.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replaces the result op with a new op that is created without verification.
Dead code analysis analyzes control-flow, as understood by RegionBranchOpInterface and BranchOpInterf...
Integer range analysis determines the integer value range of SSA values using operations that define ...
This lattice element represents the integer value range of an SSA value.
std::unique_ptr< Pass > createIntRangeOptimizationsPass()
Create a pass which do optimizations based on integer range analysis.
void populateIntRangeOptimizationsPatterns(RewritePatternSet &patterns, DataFlowSolver &solver)
Add patterns for int range based optimizations.
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult applyPatternsAndFoldGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig())
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...