34 IntegerType inputType, outputType;
38 "input type is a vector but output type is an integer");
41 return op.emitError(
"input and output vectors are of incompatible shape");
44 inputType = cast<IntegerType>(
45 cast<VectorType>(op.getArg().getType()).getElementType());
46 outputType = cast<IntegerType>(
47 cast<VectorType>(op.getResult().getType()).getElementType());
51 inputType = cast<IntegerType>(op.getArg().getType());
52 outputType = dyn_cast<IntegerType>(op.getResult().getType());
55 "input type is an integer but output type is a vector");
58 if (outputType.getWidth() <= inputType.getWidth())
59 return op.emitError(
"integer width of the output type is smaller or "
60 "equal to the integer width of the input type");
71 auto arg = dyn_cast_or_null<IntegerAttr>(adaptor.getArg());
75 size_t targetSize = cast<IntegerType>(
getType()).getWidth();
76 return IntegerAttr::get(
getType(), arg.getValue().zext(targetSize));
92 typename T::FoldAdaptor adaptor) {
94 if (castOp.getArg().getType() == castOp.getType())
95 return castOp.getArg();
96 if (
auto prev = castOp.getArg().template getDefiningOp<T>()) {
98 if (prev.getArg().getType() == castOp.getType())
101 castOp.getArgMutable().set(prev.getArg());
102 return Value{castOp};
107OpFoldResult LLVM::BitcastOp::fold(FoldAdaptor adaptor) {
111LogicalResult LLVM::BitcastOp::verify() {
117 if (isa<LLVMByteType>(srcElemType) || isa<LLVMByteType>(dstElemType))
120 auto resultType = llvm::dyn_cast<LLVMPointerType>(dstElemType);
121 auto sourceType = llvm::dyn_cast<LLVMPointerType>(srcElemType);
125 if (
static_cast<bool>(resultType) !=
static_cast<bool>(sourceType))
126 return emitOpError(
"can only cast pointers from and to pointers");
131 auto isVector = llvm::IsaPred<VectorType>;
135 if (isVector(getResult().
getType()) && !isVector(getArg().
getType()))
136 return emitOpError(
"cannot cast pointer to vector of pointers");
138 if (!isVector(getResult().
getType()) && isVector(getArg().
getType()))
139 return emitOpError(
"cannot cast vector of pointers to pointer");
143 if (resultType.getAddressSpace() != sourceType.getAddressSpace())
144 return emitOpError(
"cannot cast pointers of different address spaces, "
145 "use 'llvm.addrspacecast' instead");
150LogicalResult LLVM::PtrToAddrOp::verify() {
156 std::optional<unsigned> width = dataLayout.getTypeIndexBitwidth(pointerType);
157 assert(width &&
"pointers always return an index bitwidth");
158 if (width != integerType.getWidth())
159 return emitOpError(
"bit-width of integer result type ")
160 << integerType <<
" must match the pointer bitwidth (" << *width
161 <<
") specified in the datalayout";
170OpFoldResult LLVM::AddrSpaceCastOp::fold(FoldAdaptor adaptor) {
174Value LLVM::AddrSpaceCastOp::getViewSource() {
return getArg(); }
176bool LLVM::BitcastOp::canUsesBeRemoved(
188bool LLVM::AddrSpaceCastOp::canUsesBeRemoved(
200#define GET_OP_CLASSES
201#include "mlir/Dialect/LLVMIR/LLVMConversionOps.cpp.inc"
static OpFoldResult foldChainableCast(T castOp, typename T::FoldAdaptor adaptor)
Folds a cast op that can be chained.
static LogicalResult verifyExtOp(ExtOp op)
Verifies that the given extension operation operates on consistent scalars or vectors,...
The main mechanism for performing data layout queries.
static DataLayout closest(Operation *op)
Returns the layout of the closest parent operation carrying layout info.
This class helps build Operations.
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 extractVectorElementType(Type type)
Returns the elemental type of any LLVM-compatible vector type or self.
bool isCompatibleVectorType(Type type)
Returns true if the given type is a vector type compatible with the LLVM dialect.
bool forwardToUsers(Operation *op, SmallVectorImpl< OpOperand * > &newBlockingUses)
Conditions the deletion of the operation to the removal of all its uses.
llvm::ElementCount getVectorNumElements(Type type)
Returns the element count of any LLVM-compatible vector type.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
DeletionKind
Returned by operation promotion logic requesting the deletion of an operation.
@ Delete
Delete the operation after promotion.