15 #include "llvm/ADT/SmallBitVector.h"
43 llvm::SmallBitVector dimsToProject(shape.size());
44 for (
unsigned pos = 0, e = shape.size(); pos < e && rank > 0; ++pos) {
45 if (shape[pos] == 1) {
46 dimsToProject.set(pos);
55 if (
auto value = ofr.dyn_cast<
Value>())
57 auto attr = ofr.dyn_cast<
Attribute>().dyn_cast<IntegerAttr>();
58 assert(attr &&
"expect the op fold result casts to an integer attribute");
64 if (targetType == value.
getType())
67 bool targetIsIndex = targetType.
isIndex();
69 if (targetIsIndex ^ valueIsIndex)
70 return b.
create<arith::IndexCastOp>(loc, targetType, value);
72 auto targetIntegerType = targetType.
dyn_cast<IntegerType>();
74 assert(targetIntegerType && valueIntegerType &&
75 "unexpected cast between types other than integers and index");
76 assert(targetIntegerType.getSignedness() == valueIntegerType.getSignedness());
78 if (targetIntegerType.getWidth() > valueIntegerType.getWidth())
79 return b.
create<arith::ExtSIOp>(loc, targetIntegerType, value);
80 return b.
create<arith::TruncIOp>(loc, targetIntegerType, value);
84 Type toType,
bool isUnsignedCast) {
85 if (operand.
getType() == toType)
87 if (
auto toIntType = toType.
dyn_cast<IntegerType>()) {
91 return b.
create<arith::FPToUIOp>(loc, toType, operand);
92 return b.
create<arith::FPToSIOp>(loc, toType, operand);
96 return b.
create<arith::IndexCastOp>(loc, toType, operand);
99 if (toIntType.getWidth() > fromIntType.getWidth()) {
101 return b.
create<arith::ExtUIOp>(loc, toType, operand);
102 return b.
create<arith::ExtSIOp>(loc, toType, operand);
104 if (toIntType.getWidth() < fromIntType.getWidth())
105 return b.
create<arith::TruncIOp>(loc, toType, operand);
112 return b.
create<arith::UIToFPOp>(loc, toFloatType, operand);
113 return b.
create<arith::SIToFPOp>(loc, toFloatType, operand);
116 if (toFloatType.getWidth() > fromFloatType.getWidth())
117 return b.
create<arith::ExtFOp>(loc, toFloatType, operand);
118 if (toFloatType.getWidth() < fromFloatType.getWidth())
119 return b.
create<arith::TruncFOp>(loc, toFloatType, operand);
130 return llvm::to_vector<4>(
137 return b.
create<arith::AndIOp>(loc, lhs, rhs);
141 return b.
create<arith::AddFOp>(loc, lhs, rhs);
142 return b.
create<arith::AddIOp>(loc, lhs, rhs);
146 return b.
create<arith::SubFOp>(loc, lhs, rhs);
147 return b.
create<arith::SubIOp>(loc, lhs, rhs);
151 return b.
create<arith::MulFOp>(loc, lhs, rhs);
152 return b.
create<arith::MulIOp>(loc, lhs, rhs);
156 return b.
create<arith::CmpFOp>(loc, arith::CmpFPredicate::OGT, lhs, rhs);
157 return b.
create<arith::CmpIOp>(loc, arith::CmpIPredicate::sgt, lhs, rhs);
161 return b.
create<arith::CmpFOp>(loc, arith::CmpFPredicate::OLT, lhs, rhs);
162 return b.
create<arith::CmpIOp>(loc, arith::CmpIPredicate::slt, lhs, rhs);
165 return b.
create<arith::SelectOp>(loc, cmp, lhs, rhs);
Attributes are known-constant values of operations.
IntegerAttr getIndexAttr(int64_t value)
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.
This class represents a single result from folding an operation.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
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.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Specialization of arith.constant op that returns an integer of index type.
Include the generated interface declarations.
InFlightDiagnostic emitWarning(Location loc)
Utility method to emit a warning message using this location.
Value convertScalarToDtype(OpBuilder &b, Location loc, Value operand, Type toType, bool isUnsignedCast)
Converts a scalar value operand to type toType.
void canonicalizeSubViewPart(SmallVectorImpl< OpFoldResult > &values, function_ref< bool(int64_t)> isDynamic)
Detects the values produced by a ConstantIndexOp and places the new constant in place of the correspo...
Value getValueOrCreateCastToIndexLike(OpBuilder &b, Location loc, Type targetType, Value value)
Create a cast from an index-like value (index or integer) to another index-like value.
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
llvm::SmallBitVector getPositionsOfShapeOne(unsigned rank, ArrayRef< int64_t > shape)
detail::op_matcher< arith::ConstantIndexOp > matchConstantIndex()
Matches a ConstantIndexOp.
Value mul(Value lhs, Value rhs)
Value _and(Value lhs, Value rhs)
Value slt(Value lhs, Value rhs)
Value select(Value cmp, Value lhs, Value rhs)
Value add(Value lhs, Value rhs)
Value sgt(Value lhs, Value rhs)
Value sub(Value lhs, Value rhs)
The matcher that matches a certain kind of op.