9#ifndef MLIR_CONVERSION_ARITHATTRTOLLVM_ATTRTOLLVMCONVERTER_H
10#define MLIR_CONVERSION_ARITHATTRTOLLVM_ATTRTOLLVMCONVERTER_H
27LLVM::FastmathFlagsAttr
31LLVM::IntegerOverflowFlags
45LLVM::FPExceptionBehaviorAttr
50template <
typename SourceOp,
typename TargetOp>
55 convertedAttr(srcOp->getDiscardableAttrDictionary()) {
56 auto arithFMFAttr = srcOp.getFastMathFlagsAttr();
58 StringRef targetAttrName = TargetOp::getFastmathAttrName();
65 return convertedAttr.getAttrs();
71 typename TargetOp::Properties properties{};
72 TargetOp::populateDefaultProperties(
73 OperationName(TargetOp::getOperationName(), context), properties);
76 TargetOp::setPropertiesFromAttr(properties, propertiesAttr, [&]() {
77 return emitError(UnknownLoc::get(context));
79 assert(succeeded(
result) &&
"failed to convert target properties");
88 DictionaryAttr propertiesAttr;
94template <
typename SourceOp,
typename TargetOp>
98 : convertedAttr(srcOp->getDiscardableAttrDictionary()) {
99 using IntegerOverflowFlagsAttr = LLVM::IntegerOverflowFlagsAttr;
101 if (
auto arithAttr = srcOp.getOverflowAttr()) {
102 auto llvmFlag = convertArithOverflowFlagsToLLVM(arithAttr.getValue());
106 MLIRContext *ctx = srcOp.getOperation()->getContext();
108 auto llvmFlagAttr = IntegerOverflowFlagsAttr::get(ctx, llvmFlag);
109 StringRef llvmAttrName = TargetOp::getOverflowFlagsAttrName();
110 NamedAttribute attr{llvmAttrName, llvmFlagAttr};
113 propertiesAttr =
b.getDictionaryAttr(
ArrayRef(attr));
121 DictionaryAttr propertiesAttr;
127template <
typename SourceOp,
typename TargetOp>
131 : convertedAttr(srcOp->getDiscardableAttrDictionary()) {
132 if (!srcOp.getNonNeg())
134 MLIRContext *ctx = srcOp.getOperation()->getContext();
137 propertiesAttr =
b.getDictionaryAttr(
ArrayRef(attr));
144 DictionaryAttr propertiesAttr;
147template <
typename SourceOp,
typename TargetOp>
149 static_assert(TargetOp::template hasTrait<
150 LLVM::FPExceptionBehaviorOpInterface::Trait>(),
151 "Target constrained FP operations must implement "
152 "LLVM::FPExceptionBehaviorOpInterface");
156 : convertedAttr(srcOp->getDiscardableAttrDictionary()) {
157 if constexpr (TargetOp::template hasTrait<
158 LLVM::RoundingModeOpInterface::Trait>()) {
159 auto arithAttr = srcOp.getRoundingModeAttr();
160 convertedAttr.set(TargetOp::getRoundingModeAttrName(),
165 convertedAttr.set(TargetOp::getFPExceptionBehaviorAttrName(),
Attributes are known-constant values of operations.
This class is a general helper class for creating context-global objects like types,...
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
NamedAttribute represents a combination of a name and an Attribute value.
TargetOp::Properties getProperties() const
ArrayRef< NamedAttribute > getDiscardableAttrs() const
ArrayRef< NamedAttribute > getAttrs() const
Attribute getPropAttr() const
AttrConvertFastMathToLLVM(SourceOp srcOp)
Attribute getPropAttr() const
AttrConvertNonNegToLLVM(SourceOp srcOp)
ArrayRef< NamedAttribute > getAttrs() const
AttrConvertOverflowToLLVM(SourceOp srcOp)
Attribute getPropAttr() const
ArrayRef< NamedAttribute > getAttrs() const
AttrConverterConstrainedFPToLLVM(SourceOp srcOp)
ArrayRef< NamedAttribute > getAttrs() const
Attribute getPropAttr() const
LLVM::FPExceptionBehaviorAttr getLLVMDefaultFPExceptionBehavior(MLIRContext &context)
Returns an attribute for the default LLVM FP exception behavior.
LLVM::FastmathFlagsAttr convertArithFastMathAttrToLLVM(arith::FastMathFlagsAttr fmfAttr)
Creates an LLVM fastmath attribute from a given arithmetic fastmath attribute.
LLVM::RoundingMode convertArithRoundingModeToLLVM(arith::RoundingMode roundingMode)
Creates an LLVM rounding mode enum value from a given arithmetic rounding mode enum value.
LLVM::IntegerOverflowFlags convertArithOverflowFlagsToLLVM(arith::IntegerOverflowFlags arithFlags)
Maps arithmetic overflow enum values to LLVM enum values.
LLVM::FastmathFlags convertArithFastMathFlagsToLLVM(arith::FastMathFlags arithFMF)
Maps arithmetic fastmath enum values to LLVM enum values.
LLVM::RoundingModeAttr convertArithRoundingModeAttrToLLVM(arith::RoundingModeAttr roundingModeAttr)
Creates an LLVM rounding mode attribute from a given arithmetic rounding mode attribute.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.