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)
111 auto input1Ty = llvm::dyn_cast<RankedTensorType>(input1.
getType());
112 auto input2Ty = llvm::dyn_cast<RankedTensorType>(input2.
getType());
114 if (!input1Ty || !input2Ty) {
118 int64_t input1Rank = input1Ty.getRank();
119 int64_t input2Rank = input2Ty.getRank();
121 if (input1Rank == input2Rank)
124 Value higherTensorValue, lowerTensorValue;
125 if (input1Rank > input2Rank) {
126 higherTensorValue = input1;
127 lowerTensorValue = input2;
129 higherTensorValue = input2;
130 lowerTensorValue = input1;
134 llvm::cast<RankedTensorType>(higherTensorValue.
getType()).getShape();
136 llvm::cast<RankedTensorType>(lowerTensorValue.
getType()).getShape();
140 if (computeReshapeOutput(higherRankShape, lowerRankShape, reshapeOutputShape)
144 auto reshapeInputType =
145 llvm::cast<RankedTensorType>(lowerTensorValue.
getType());
149 auto reshapeLower = builder.
create<tosa::ReshapeOp>(
150 reshapeOutputType, lowerTensorValue,
153 if (input1Rank > input2Rank) {
154 input1 = higherTensorValue;
155 input2 = reshapeLower.getResult();
157 input1 = reshapeLower.getResult();
158 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)
ImplicitLocOpBuilder maintains a 'current location', allowing use of the create<> method without spec...
OpTy create(Args &&...args)
Create an operation of specific op type at the current insertion point and location.
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.