22 utils::IteratorType::parallel);
28 for (
auto value : values)
30 condensedValues.push_back(value);
31 return condensedValues;
36 Value minValue = rewriter.
create<arith::MinimumFOp>(loc, arg,
max);
37 return rewriter.
create<arith::MaximumFOp>(loc, minValue,
min);
43 rewriter.
create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt, arg,
min);
45 rewriter.
create<arith::SelectOp>(loc, smallerThanMin,
min, arg);
47 rewriter.
create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt,
max, arg);
48 return rewriter.
create<arith::SelectOp>(loc, largerThanMax,
max, minOrArg);
52 uint64_t bitwidth = ty.getIntOrFloatBitWidth();
53 if (ty.getSignedness() == IntegerType::Unsigned) {
54 uint64_t uvalue = value;
55 APInt intMin = APInt::getMinValue(bitwidth);
56 APInt intMax = APInt::getMaxValue(bitwidth);
57 return uvalue >= intMin.getZExtValue() && uvalue <= intMax.getZExtValue();
60 APInt intMin = APInt::getSignedMinValue(bitwidth);
61 APInt intMax = APInt::getSignedMaxValue(bitwidth);
62 return value >= intMin.getSExtValue() && value <= intMax.getSExtValue();
79 int64_t higherRank = higherRankShape.size();
80 int64_t lowerRank = lowerRankShape.size();
82 reshapeOutputShape.assign(higherRank, 1);
84 int64_t higherRankDim;
87 for (int64_t i = higherRank - 1,
j = lowerRank - 1; i >= 0 &&
j >= 0;
89 higherRankDim = higherRankShape[i];
90 lowerRankDim = lowerRankShape[
j];
92 if (lowerRankDim == 1 && higherRankDim > 1)
93 reshapeOutputShape[i] = 1;
94 else if ((lowerRankDim > 1 && higherRankDim == 1) ||
95 (lowerRankDim == higherRankDim))
96 reshapeOutputShape[i] = lowerRankDim;
97 else if (higherRankDim != lowerRankDim)
106 auto input1Ty = llvm::dyn_cast<RankedTensorType>(input1.
getType());
107 auto input2Ty = llvm::dyn_cast<RankedTensorType>(input2.
getType());
109 if (!input1Ty || !input2Ty) {
113 int64_t input1Rank = input1Ty.getRank();
114 int64_t input2Rank = input2Ty.getRank();
116 if (input1Rank == input2Rank)
119 Value higherTensorValue, lowerTensorValue;
120 if (input1Rank > input2Rank) {
121 higherTensorValue = input1;
122 lowerTensorValue = input2;
124 higherTensorValue = input2;
125 lowerTensorValue = input1;
129 llvm::cast<RankedTensorType>(higherTensorValue.
getType()).getShape();
131 llvm::cast<RankedTensorType>(lowerTensorValue.
getType()).getShape();
135 if (computeReshapeOutput(higherRankShape, lowerRankShape, reshapeOutputShape)
139 auto reshapeInputType =
140 llvm::cast<RankedTensorType>(lowerTensorValue.
getType());
144 auto reshapeLower = rewriter.
create<tosa::ReshapeOp>(
145 loc, reshapeOutputType, lowerTensorValue,
148 if (input1Rank > input2Rank) {
149 input1 = higherTensorValue;
150 input2 = reshapeLower.getResult();
152 input1 = reshapeLower.getResult();
153 input2 = higherTensorValue;
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
DenseI64ArrayAttr getDenseI64ArrayAttr(ArrayRef< int64_t > values)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Value clampFloatHelper(Location loc, Value arg, Value min, Value max, OpBuilder &rewriter)
SmallVector< utils::IteratorType > getNParallelLoopsAttrs(unsigned nParallelLoops)
SmallVector< Value > condenseValues(const SmallVector< Value > &values)
LogicalResult EqualizeRanks(PatternRewriter &rewriter, Location loc, Value &input1, Value &input2)
Common code to create the reshape op where necessary to make the rank of two values equal.
Value clampIntHelper(Location loc, Value arg, Value min, Value max, OpBuilder &rewriter)
bool validIntegerRange(IntegerType ty, int64_t value)
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
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.
Eliminates variable at the specified position using Fourier-Motzkin variable elimination.