9#ifndef MLIR_CONVERSION_ARITHCOMMON_ATTRTOLLVMCONVERTER_H
10#define MLIR_CONVERSION_ARITHCOMMON_ATTRTOLLVMCONVERTER_H
28LLVM::FastmathFlagsAttr
32LLVM::IntegerOverflowFlags
46LLVM::FPExceptionBehaviorAttr
51template <
typename SourceOp,
typename TargetOp>
56 convertedAttr(srcOp->getDiscardableAttrDictionary()) {
57 auto arithFMFAttr = srcOp.getFastMathFlagsAttr();
59 StringRef targetAttrName = TargetOp::getFastmathAttrName();
66 return convertedAttr.getAttrs();
72 typename TargetOp::Properties properties{};
73 TargetOp::populateDefaultProperties(
74 OperationName(TargetOp::getOperationName(), context), properties);
77 TargetOp::setPropertiesFromAttr(properties, propertiesAttr, [&]() {
78 return emitError(UnknownLoc::get(context));
80 assert(succeeded(
result) &&
"failed to convert target properties");
89 DictionaryAttr propertiesAttr;
95template <
typename SourceOp,
typename TargetOp>
99 : convertedAttr(srcOp->getDiscardableAttrDictionary()) {
100 using IntegerOverflowFlagsAttr = LLVM::IntegerOverflowFlagsAttr;
102 if (
auto arithAttr = srcOp.getOverflowAttr()) {
103 auto llvmFlag = convertArithOverflowFlagsToLLVM(arithAttr.getValue());
107 MLIRContext *ctx = srcOp.getOperation()->getContext();
109 auto llvmFlagAttr = IntegerOverflowFlagsAttr::get(ctx, llvmFlag);
110 StringRef llvmAttrName = TargetOp::getOverflowFlagsAttrName();
111 NamedAttribute attr{llvmAttrName, llvmFlagAttr};
114 propertiesAttr =
b.getDictionaryAttr(
ArrayRef(attr));
122 DictionaryAttr propertiesAttr;
128template <
typename SourceOp,
typename TargetOp>
132 : convertedAttr(srcOp->getDiscardableAttrDictionary()) {
133 if (!srcOp.getNonNeg())
135 MLIRContext *ctx = srcOp.getOperation()->getContext();
138 propertiesAttr =
b.getDictionaryAttr(
ArrayRef(attr));
145 DictionaryAttr propertiesAttr;
148template <
typename SourceOp,
typename TargetOp>
150 static_assert(TargetOp::template hasTrait<
151 LLVM::FPExceptionBehaviorOpInterface::Trait>(),
152 "Target constrained FP operations must implement "
153 "LLVM::FPExceptionBehaviorOpInterface");
157 : convertedAttr(srcOp->getDiscardableAttrDictionary()) {
158 if constexpr (TargetOp::template hasTrait<
159 LLVM::RoundingModeOpInterface::Trait>()) {
160 auto arithAttr = srcOp.getRoundingModeAttr();
161 convertedAttr.set(TargetOp::getRoundingModeAttrName(),
166 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.