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 auto minOrArg = rewriter.
create<arith::MaxUIOp>(loc,
min, arg);
44 return rewriter.
create<arith::MinUIOp>(loc,
max, minOrArg);
46 auto minOrArg = rewriter.
create<arith::MaxSIOp>(loc,
min, arg);
47 return rewriter.
create<arith::MinSIOp>(loc,
max, minOrArg);
51 uint64_t bitwidth = ty.getIntOrFloatBitWidth();
52 if (ty.getSignedness() == IntegerType::Unsigned) {
53 uint64_t uvalue = value;
54 APInt intMin = APInt::getMinValue(bitwidth);
55 APInt intMax = APInt::getMaxValue(bitwidth);
56 return uvalue >= intMin.getZExtValue() && uvalue <= intMax.getZExtValue();
59 APInt intMin = APInt::getSignedMinValue(bitwidth);
60 APInt intMax = APInt::getSignedMaxValue(bitwidth);
61 return value >= intMin.getSExtValue() && value <= intMax.getSExtValue();
78 int64_t higherRank = higherRankShape.size();
79 int64_t lowerRank = lowerRankShape.size();
81 reshapeOutputShape.assign(higherRank, 1);
83 int64_t higherRankDim;
86 for (int64_t i = higherRank - 1,
j = lowerRank - 1; i >= 0 &&
j >= 0;
88 higherRankDim = higherRankShape[i];
89 lowerRankDim = lowerRankShape[
j];
91 if (lowerRankDim == 1 && higherRankDim > 1)
92 reshapeOutputShape[i] = 1;
93 else if ((lowerRankDim > 1 && higherRankDim == 1) ||
94 (lowerRankDim == higherRankDim))
95 reshapeOutputShape[i] = lowerRankDim;
96 else if (higherRankDim != lowerRankDim)
105 auto input1Ty = llvm::dyn_cast<RankedTensorType>(input1.
getType());
106 auto input2Ty = llvm::dyn_cast<RankedTensorType>(input2.
getType());
108 if (!input1Ty || !input2Ty) {
112 int64_t input1Rank = input1Ty.getRank();
113 int64_t input2Rank = input2Ty.getRank();
115 if (input1Rank == input2Rank)
118 Value higherTensorValue, lowerTensorValue;
119 if (input1Rank > input2Rank) {
120 higherTensorValue = input1;
121 lowerTensorValue = input2;
123 higherTensorValue = input2;
124 lowerTensorValue = input1;
128 llvm::cast<RankedTensorType>(higherTensorValue.
getType()).getShape();
130 llvm::cast<RankedTensorType>(lowerTensorValue.
getType()).getShape();
134 if (computeReshapeOutput(higherRankShape, lowerRankShape, reshapeOutputShape)
138 auto reshapeInputType =
139 llvm::cast<RankedTensorType>(lowerTensorValue.
getType());
143 auto reshapeLower = rewriter.
create<tosa::ReshapeOp>(
144 loc, reshapeOutputType, lowerTensorValue,
147 if (input1Rank > input2Rank) {
148 input1 = higherTensorValue;
149 input2 = reshapeLower.getResult();
151 input1 = reshapeLower.getResult();
152 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.
bool validIntegerRange(IntegerType ty, int64_t value)
Value clampIntHelper(Location loc, Value arg, Value min, Value max, OpBuilder &rewriter, bool isUnsigned)
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Eliminates variable at the specified position using Fourier-Motzkin variable elimination.