/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |* *| |* Op Declarations *| |* *| |* Automatically generated file, do not edit! *| |* From: QuantOps.td *| |* *| \*===----------------------------------------------------------------------===*/ namespace mlir::quant { /// Dequantize cast operation /// Convert an input quantized value into its expressed floating-point value. /// The dequantization process consists of the following steps: /// /// ``` /// def dequantize(quantizedValue: quantizedType) -> expressedType: /// storedValue = reinterpretCast(quantizedValue, storageType) /// storedValueFloat = convertIntToFloat(storedValue, expressedType) /// zeroPointFloat = convertIntToFloat(zeroPoint, expressedType) /// expressedValue = (storedValueFloat - zeroPointFloat) * scale /// return expressedValue /// ``` /// /// Here, `storageType`, `expressedType`, `scale`, and `zeroPoint` are obtained /// from the corresponding parameters encoded in `quantizedType`. For /// per-channel quantization, the appropriate `scale` and `zeroPoint` values /// are used for each tensor element computation according to the channel the /// element belongs to. /// /// The numerical results produced by the algorithm above may vary depending on /// the rounding methods used by `convertIntToFloat()`, subtraction (`-`), and /// multiplication (`*`). This operation does not define specific rounding /// methods; instead, it is the responsibility of a transform pipeline to /// determine which rounding method to apply when this operation is broken down /// into lower-level dialects. /// /// The operation must satisfy the following syntactic constraints: /// /// - Operand `input` must be a scalar or tensor of type `!quant.uniform`. /// /// - The result type must be a floating-point scalar or tensor. /// /// - The `expressedType` parameter of the `!quant.uniform` type of the input /// must match the floating-point type of the result. /// /// - The operand and result types must be both scalars or both tensors. If /// tensors, they must be both ranked or both unranked. If ranked, both must /// have the same shape, including matching static and dynamic dimensions. /// /// - If the operand uses per-channel quantization, its `!quant.uniform` type /// must adhere to the [Per-axis quantization /// integrity](#per-axis-quantization-integrity) guidelines. /// /// Examples: /// /// ``` /// // Dequantize a scalar quantized value /// %result = quant.dcast %input : !quant.uniform to f32 /// /// // Dequantize a dynamically shaped tensor of quantized values /// %result = quant.dcast %input : tensor> to tensor /// /// // Dequantize an unranked tensor using per-axis quantization information /// %result = quant.dcast %input : tensor<*x!quant.uniform> to tensor<*xf32> /// ``` class DequantizeCastOp; } // namespace mlir::quant namespace mlir::quant { /// Quantize cast operation /// Convert a floating-point value to a quantized type. The quantization /// process consists of the following steps: /// /// ``` /// def quantize(expressedValue: expressedType) -> quantizedType: /// zeroPointFloat = convertIntToFloat(zeroPoint, expressedType) /// scaledValue = expressedValue / scale /// storedValueFloat = scaledValue + zeroPointFloat /// storedValue = convertFloatToInt(storedValueFloat, storageType) /// storedValueClamped = clamp(storedValue, storageMin, storageMax) /// quantizedValue = reinterpretCast(storedValueClamped, quantizedType) /// return quantizedValue /// ``` /// /// Here, `storageType`, `storageMin`, `storageMax`, `expressedType`, `scale`, /// and `zeroPoint` are obtained from the corresponding parameters encoded in /// `quantizedType`. For per-channel quantization, the appropriate `scale` and /// `zeroPoint` values are used for each tensor element computation according /// to the channel the element belongs to. /// /// The numerical results produced by the algorithm above may vary depending on /// the rounding methods used by `convertIntToFloat()`, `convertFloatToInt()`, /// `clamp()`, division (`/`), and addition (`+`). This operation does not /// define specific rounding methods; instead, it is the responsibility of a /// transform pipeline to determine which rounding method to apply when this /// operation is broken down into lower-level dialects. /// /// The operation must satisfy the following syntactic constraints: /// /// - Operand `input` must be a floating-point scalar or tensor. /// /// - The result type must be a scalar or tensor of type `!quant.uniform`. /// /// - The `expressedType` parameter in the `!quant.uniform` type of the result /// must match the floating-point type of the input. /// /// - The operand and result types must be both scalars or both tensors. If /// tensors, they must be both ranked or both unranked. If ranked, both must /// have the same shape, including matching static and dynamic dimensions. /// /// - If the result uses per-channel quantization, its `!quant.uniform` type /// must adhere to the [Per-axis quantization /// integrity](#per-axis-quantization-integrity) guidelines. /// /// Examples: /// /// ``` /// // Quantize a scalar floating-point value /// %result = quant.qcast %input : f32 to !quant.uniform /// /// // Quantize a dynamically shaped tensor of quantized values /// %result = quant.qcast %input : tensor to tensor> /// /// // Quantize an unranked tensor using per-axis quantization information /// %result = quant.qcast %input : tensor<*xf32> to tensor<*x!quant.uniform> /// ``` class QuantizeCastOp; } // namespace mlir::quant namespace mlir::quant { /// Storage cast operation /// Convert a value from a quantized type to the corresponding signless integer /// storage type, or vice versa. This conversion simply involves a /// reinterpretation of the input bits and does not involve any data /// manipulation. /// /// The following syntactic restrictions must be met: /// /// - Operand `input` must be a scalar or tensor of a signless integer or /// `!quant.uniform` type. /// /// - The result must be a scalar or tensor of a signless integer or /// `!quant.uniform` type. /// /// - If the operand is a scalar or tensor of type integer, the result must be /// a scalar or tensor of type `!quant.uniform`, and vice versa. /// /// - The operand and result must be both scalars or both tensors. If tensors, /// they must be both ranked or both unranked. If ranked, both must have the /// same shape, including matching static and dynamic dimensions. /// /// - The width of the `storageType` parameter of the quantized type of the /// operand or result must match the width of the signless integer type of /// the operand or result. /// /// - If the operand or result uses per-channel quantization, its /// `!quant.uniform` type must adhere to the [Per-axis quantization /// integrity](#per-axis-quantization-integrity) guidelines. /// /// Examples: /// /// ``` /// // Cast a scalar quantized value into its storage type /// %result = quant.scast %input : !quant.uniform to i8 /// /// // Cast a dynamically shaped tensor of quantized values into their storage type /// %result = quant.scast %input : tensor> to tensor /// /// // Cast an unranked tensor of signless integers into a quantized type using /// // per-channel quantization /// %result = quant.scast %input : tensor<*xi8> to tensor<*x!quant.uniform> /// ``` class StorageCastOp; } // namespace mlir::quant #ifdef GET_OP_CLASSES #undef GET_OP_CLASSES namespace mlir::quant { //===----------------------------------------------------------------------===// // ::mlir::quant::DequantizeCastOp declarations //===----------------------------------------------------------------------===// namespace detail { class DequantizeCastOpGenericAdaptorBase { public: using Properties = ::mlir::EmptyProperties; protected: ::mlir::DictionaryAttr odsAttrs; ::std::optional<::mlir::OperationName> odsOpName; Properties properties; ::mlir::RegionRange odsRegions; public: DequantizeCastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) odsOpName.emplace("quant.dcast", odsAttrs.getContext()); } DequantizeCastOpGenericAdaptorBase(DequantizeCastOp op); std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { return {index, 1}; } const Properties &getProperties() { return properties; } ::mlir::DictionaryAttr getAttributes() { return odsAttrs; } }; } // namespace detail template class DequantizeCastOpGenericAdaptor : public detail::DequantizeCastOpGenericAdaptorBase { using ValueT = ::llvm::detail::ValueOfRange; using Base = detail::DequantizeCastOpGenericAdaptorBase; static constexpr int odsIndex_input = 0; public: DequantizeCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} DequantizeCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::PropertyRef properties, ::mlir::RegionRange regions = {}) : DequantizeCastOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} DequantizeCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : DequantizeCastOpGenericAdaptor(values, attrs, Properties{}, {}) {} DequantizeCastOpGenericAdaptor(RangeT values, const DequantizeCastOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {} template >> DequantizeCastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} std::pair getODSOperandIndexAndLength(unsigned index) { return Base::getODSOperandIndexAndLength(index, odsOperands.size()); } RangeT getODSOperands(unsigned index) { auto valueRange = getODSOperandIndexAndLength(index); return {std::next(odsOperands.begin(), valueRange.first), std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; } ValueT getInput() { return (*getODSOperands(0).begin()); } RangeT getOperands() { return odsOperands; } private: RangeT odsOperands; }; class DequantizeCastOpAdaptor : public DequantizeCastOpGenericAdaptor<::mlir::ValueRange> { public: using DequantizeCastOpGenericAdaptor::DequantizeCastOpGenericAdaptor; DequantizeCastOpAdaptor(DequantizeCastOp op); ::llvm::LogicalResult verify(::mlir::Location loc); }; class DequantizeCastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { public: using Op::Op; using Op::print; using Adaptor = DequantizeCastOpAdaptor; template using GenericAdaptor = DequantizeCastOpGenericAdaptor; using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; static constexpr int odsIndex_input = 0; using Properties = FoldAdaptor::Properties; static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { return {}; } static constexpr ::llvm::StringLiteral getOperationName() { return ::llvm::StringLiteral("quant.dcast"); } std::pair getODSOperandIndexAndLength(unsigned index) { return {index, 1}; } ::mlir::Operation::operand_range getODSOperands(unsigned index) { auto valueRange = getODSOperandIndexAndLength(index); return {std::next(getOperation()->operand_begin(), valueRange.first), std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; } ::mlir::TypedValue<::mlir::Type> getInput() { return ::llvm::cast<::mlir::TypedValue<::mlir::Type>>(*getODSOperands(0).begin()); } ::mlir::OpOperand &getInputMutable() { auto range = getODSOperandIndexAndLength(0); return getOperation()->getOpOperand(range.first); } std::pair getODSResultIndexAndLength(unsigned index) { return {index, 1}; } ::mlir::Operation::result_range getODSResults(unsigned index) { auto valueRange = getODSResultIndexAndLength(index); return {std::next(getOperation()->result_begin(), valueRange.first), std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; } ::mlir::TypedValue<::mlir::Type> getResult() { return ::llvm::cast<::mlir::TypedValue<::mlir::Type>>(*getODSResults(0).begin()); } static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); static llvm::hash_code computePropertiesHash(const Properties &prop); static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::mlir::Value input); static DequantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, ::mlir::Value input); static DequantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type result, ::mlir::Value input); static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); static DequantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value input); static DequantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value input); static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static DequantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static DequantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); static DequantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); static DequantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); ::llvm::LogicalResult verifyInvariantsImpl(); ::llvm::LogicalResult verifyInvariants(); ::llvm::LogicalResult verify(); ::mlir::OpFoldResult fold(FoldAdaptor adaptor); static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); void print(::mlir::OpAsmPrinter &_odsPrinter); void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); public: /// Return the float type of the scalar or tensor result. FloatType getFloatType(); /// Return the quantized type of the scalar or tensor input. quant::QuantizedType getQuantizedType(); }; } // namespace mlir::quant MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::quant::DequantizeCastOp) namespace mlir::quant { //===----------------------------------------------------------------------===// // ::mlir::quant::QuantizeCastOp declarations //===----------------------------------------------------------------------===// namespace detail { class QuantizeCastOpGenericAdaptorBase { public: using Properties = ::mlir::EmptyProperties; protected: ::mlir::DictionaryAttr odsAttrs; ::std::optional<::mlir::OperationName> odsOpName; Properties properties; ::mlir::RegionRange odsRegions; public: QuantizeCastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) odsOpName.emplace("quant.qcast", odsAttrs.getContext()); } QuantizeCastOpGenericAdaptorBase(QuantizeCastOp op); std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { return {index, 1}; } const Properties &getProperties() { return properties; } ::mlir::DictionaryAttr getAttributes() { return odsAttrs; } }; } // namespace detail template class QuantizeCastOpGenericAdaptor : public detail::QuantizeCastOpGenericAdaptorBase { using ValueT = ::llvm::detail::ValueOfRange; using Base = detail::QuantizeCastOpGenericAdaptorBase; static constexpr int odsIndex_input = 0; public: QuantizeCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} QuantizeCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::PropertyRef properties, ::mlir::RegionRange regions = {}) : QuantizeCastOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} QuantizeCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : QuantizeCastOpGenericAdaptor(values, attrs, Properties{}, {}) {} QuantizeCastOpGenericAdaptor(RangeT values, const QuantizeCastOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {} template >> QuantizeCastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} std::pair getODSOperandIndexAndLength(unsigned index) { return Base::getODSOperandIndexAndLength(index, odsOperands.size()); } RangeT getODSOperands(unsigned index) { auto valueRange = getODSOperandIndexAndLength(index); return {std::next(odsOperands.begin(), valueRange.first), std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; } ValueT getInput() { return (*getODSOperands(0).begin()); } RangeT getOperands() { return odsOperands; } private: RangeT odsOperands; }; class QuantizeCastOpAdaptor : public QuantizeCastOpGenericAdaptor<::mlir::ValueRange> { public: using QuantizeCastOpGenericAdaptor::QuantizeCastOpGenericAdaptor; QuantizeCastOpAdaptor(QuantizeCastOp op); ::llvm::LogicalResult verify(::mlir::Location loc); }; class QuantizeCastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { public: using Op::Op; using Op::print; using Adaptor = QuantizeCastOpAdaptor; template using GenericAdaptor = QuantizeCastOpGenericAdaptor; using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; static constexpr int odsIndex_input = 0; using Properties = FoldAdaptor::Properties; static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { return {}; } static constexpr ::llvm::StringLiteral getOperationName() { return ::llvm::StringLiteral("quant.qcast"); } std::pair getODSOperandIndexAndLength(unsigned index) { return {index, 1}; } ::mlir::Operation::operand_range getODSOperands(unsigned index) { auto valueRange = getODSOperandIndexAndLength(index); return {std::next(getOperation()->operand_begin(), valueRange.first), std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; } ::mlir::TypedValue<::mlir::Type> getInput() { return ::llvm::cast<::mlir::TypedValue<::mlir::Type>>(*getODSOperands(0).begin()); } ::mlir::OpOperand &getInputMutable() { auto range = getODSOperandIndexAndLength(0); return getOperation()->getOpOperand(range.first); } std::pair getODSResultIndexAndLength(unsigned index) { return {index, 1}; } ::mlir::Operation::result_range getODSResults(unsigned index) { auto valueRange = getODSResultIndexAndLength(index); return {std::next(getOperation()->result_begin(), valueRange.first), std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; } ::mlir::TypedValue<::mlir::Type> getResult() { return ::llvm::cast<::mlir::TypedValue<::mlir::Type>>(*getODSResults(0).begin()); } static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); static llvm::hash_code computePropertiesHash(const Properties &prop); static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::mlir::Value input); static QuantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, ::mlir::Value input); static QuantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type result, ::mlir::Value input); static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); static QuantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value input); static QuantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value input); static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static QuantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static QuantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); static QuantizeCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); static QuantizeCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); ::llvm::LogicalResult verifyInvariantsImpl(); ::llvm::LogicalResult verifyInvariants(); ::llvm::LogicalResult verify(); ::mlir::OpFoldResult fold(FoldAdaptor adaptor); static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); void print(::mlir::OpAsmPrinter &_odsPrinter); void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); public: /// Return the float type of the scalar or tensor input. FloatType getFloatType(); /// Return the quantized type of the scalar or tensor result. quant::QuantizedType getQuantizedType(); }; } // namespace mlir::quant MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::quant::QuantizeCastOp) namespace mlir::quant { //===----------------------------------------------------------------------===// // ::mlir::quant::StorageCastOp declarations //===----------------------------------------------------------------------===// namespace detail { class StorageCastOpGenericAdaptorBase { public: using Properties = ::mlir::EmptyProperties; protected: ::mlir::DictionaryAttr odsAttrs; ::std::optional<::mlir::OperationName> odsOpName; Properties properties; ::mlir::RegionRange odsRegions; public: StorageCastOpGenericAdaptorBase(::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : odsAttrs(attrs), properties(properties), odsRegions(regions) { if (odsAttrs) odsOpName.emplace("quant.scast", odsAttrs.getContext()); } StorageCastOpGenericAdaptorBase(StorageCastOp op); std::pair getODSOperandIndexAndLength(unsigned index, unsigned odsOperandsSize) { return {index, 1}; } const Properties &getProperties() { return properties; } ::mlir::DictionaryAttr getAttributes() { return odsAttrs; } }; } // namespace detail template class StorageCastOpGenericAdaptor : public detail::StorageCastOpGenericAdaptorBase { using ValueT = ::llvm::detail::ValueOfRange; using Base = detail::StorageCastOpGenericAdaptorBase; static constexpr int odsIndex_input = 0; public: StorageCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} StorageCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::PropertyRef properties, ::mlir::RegionRange regions = {}) : StorageCastOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} StorageCastOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : StorageCastOpGenericAdaptor(values, attrs, Properties{}, {}) {} StorageCastOpGenericAdaptor(RangeT values, const StorageCastOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {} template >> StorageCastOpGenericAdaptor(RangeT values, LateInst op) : Base(op), odsOperands(values) {} std::pair getODSOperandIndexAndLength(unsigned index) { return Base::getODSOperandIndexAndLength(index, odsOperands.size()); } RangeT getODSOperands(unsigned index) { auto valueRange = getODSOperandIndexAndLength(index); return {std::next(odsOperands.begin(), valueRange.first), std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; } ValueT getInput() { return (*getODSOperands(0).begin()); } RangeT getOperands() { return odsOperands; } private: RangeT odsOperands; }; class StorageCastOpAdaptor : public StorageCastOpGenericAdaptor<::mlir::ValueRange> { public: using StorageCastOpGenericAdaptor::StorageCastOpGenericAdaptor; StorageCastOpAdaptor(StorageCastOp op); ::llvm::LogicalResult verify(::mlir::Location loc); }; class StorageCastOp : public ::mlir::Op::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::OneOperand, ::mlir::OpTrait::OpInvariants, ::mlir::ConditionallySpeculatable::Trait, ::mlir::OpTrait::AlwaysSpeculatableImplTrait, ::mlir::MemoryEffectOpInterface::Trait> { public: using Op::Op; using Op::print; using Adaptor = StorageCastOpAdaptor; template using GenericAdaptor = StorageCastOpGenericAdaptor; using FoldAdaptor = GenericAdaptor<::llvm::ArrayRef<::mlir::Attribute>>; static constexpr int odsIndex_input = 0; using Properties = FoldAdaptor::Properties; static ::llvm::ArrayRef<::llvm::StringRef> getAttributeNames() { return {}; } static constexpr ::llvm::StringLiteral getOperationName() { return ::llvm::StringLiteral("quant.scast"); } std::pair getODSOperandIndexAndLength(unsigned index) { return {index, 1}; } ::mlir::Operation::operand_range getODSOperands(unsigned index) { auto valueRange = getODSOperandIndexAndLength(index); return {std::next(getOperation()->operand_begin(), valueRange.first), std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; } ::mlir::TypedValue<::mlir::Type> getInput() { return ::llvm::cast<::mlir::TypedValue<::mlir::Type>>(*getODSOperands(0).begin()); } ::mlir::OpOperand &getInputMutable() { auto range = getODSOperandIndexAndLength(0); return getOperation()->getOpOperand(range.first); } std::pair getODSResultIndexAndLength(unsigned index) { return {index, 1}; } ::mlir::Operation::result_range getODSResults(unsigned index) { auto valueRange = getODSResultIndexAndLength(index); return {std::next(getOperation()->result_begin(), valueRange.first), std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; } ::mlir::TypedValue<::mlir::Type> getResult() { return ::llvm::cast<::mlir::TypedValue<::mlir::Type>>(*getODSResults(0).begin()); } static ::llvm::LogicalResult setPropertiesFromAttr(Properties &prop, ::mlir::Attribute attr, ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); static ::mlir::Attribute getPropertiesAsAttr(::mlir::MLIRContext *ctx, const Properties &prop); static llvm::hash_code computePropertiesHash(const Properties &prop); static std::optional getInherentAttr(::mlir::MLIRContext *ctx, const Properties &prop, llvm::StringRef name); static void setInherentAttr(Properties &prop, llvm::StringRef name, mlir::Attribute value); static void populateInherentAttrs(::mlir::MLIRContext *ctx, const Properties &prop, ::mlir::NamedAttrList &attrs); static ::llvm::LogicalResult verifyInherentAttrs(::mlir::OperationName opName, ::mlir::NamedAttrList &attrs, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError); static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::mlir::Value input); static StorageCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::Type result, ::mlir::Value input); static StorageCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::Type result, ::mlir::Value input); static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value input); static StorageCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::Value input); static StorageCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::Value input); static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static StorageCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static StorageCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); static StorageCastOp create(::mlir::OpBuilder &builder, ::mlir::Location location, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); static StorageCastOp create(::mlir::ImplicitLocOpBuilder &builder, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {}); ::llvm::LogicalResult verifyInvariantsImpl(); ::llvm::LogicalResult verifyInvariants(); ::llvm::LogicalResult verify(); ::mlir::OpFoldResult fold(FoldAdaptor adaptor); static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); void print(::mlir::OpAsmPrinter &_odsPrinter); void getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects); public: /// Return the integer type used either in the input or the result. IntegerType getIntegerType(); /// Return the quantized type used either in the input or the result. quant::QuantizedType getQuantizedType(); }; } // namespace mlir::quant MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::quant::StorageCastOp) #endif // GET_OP_CLASSES