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);
42 auto minOrArg = rewriter.
create<arith::MaxSIOp>(loc,
min, arg);
43 return rewriter.
create<arith::MinSIOp>(loc,
max, minOrArg);
47 uint64_t bitwidth = ty.getIntOrFloatBitWidth();
48 if (ty.getSignedness() == IntegerType::Unsigned) {
49 uint64_t uvalue = value;
50 APInt intMin = APInt::getMinValue(bitwidth);
51 APInt intMax = APInt::getMaxValue(bitwidth);
52 return uvalue >= intMin.getZExtValue() && uvalue <= intMax.getZExtValue();
55 APInt intMin = APInt::getSignedMinValue(bitwidth);
56 APInt intMax = APInt::getSignedMaxValue(bitwidth);
57 return value >= intMin.getSExtValue() && value <= intMax.getSExtValue();
74 int64_t higherRank = higherRankShape.size();
75 int64_t lowerRank = lowerRankShape.size();
77 reshapeOutputShape.assign(higherRank, 1);
79 int64_t higherRankDim;
82 for (int64_t i = higherRank - 1,
j = lowerRank - 1; i >= 0 &&
j >= 0;
84 higherRankDim = higherRankShape[i];
85 lowerRankDim = lowerRankShape[
j];
87 if (lowerRankDim == 1 && higherRankDim > 1)
88 reshapeOutputShape[i] = 1;
89 else if ((lowerRankDim > 1 && higherRankDim == 1) ||
90 (lowerRankDim == higherRankDim))
91 reshapeOutputShape[i] = lowerRankDim;
92 else if (higherRankDim != lowerRankDim)
101 auto input1Ty = llvm::dyn_cast<RankedTensorType>(input1.
getType());
102 auto input2Ty = llvm::dyn_cast<RankedTensorType>(input2.
getType());
104 if (!input1Ty || !input2Ty) {
108 int64_t input1Rank = input1Ty.getRank();
109 int64_t input2Rank = input2Ty.getRank();
111 if (input1Rank == input2Rank)
114 Value higherTensorValue, lowerTensorValue;
115 if (input1Rank > input2Rank) {
116 higherTensorValue = input1;
117 lowerTensorValue = input2;
119 higherTensorValue = input2;
120 lowerTensorValue = input1;
124 llvm::cast<RankedTensorType>(higherTensorValue.
getType()).getShape();
126 llvm::cast<RankedTensorType>(lowerTensorValue.
getType()).getShape();
130 if (computeReshapeOutput(higherRankShape, lowerRankShape, reshapeOutputShape)
134 auto reshapeInputType =
135 llvm::cast<RankedTensorType>(lowerTensorValue.
getType());
139 auto reshapeLower = rewriter.
create<tosa::ReshapeOp>(
140 loc, reshapeOutputType, lowerTensorValue,
143 if (input1Rank > input2Rank) {
144 input1 = higherTensorValue;
145 input2 = reshapeLower.getResult();
147 input1 = reshapeLower.getResult();
148 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.