[Mlir-commits] [mlir] [MLIR][Arith] Add denormal attribute to binary/unary operations (PR #112700)
lorenzo chelini
llvmlistbot at llvm.org
Fri Nov 22 10:11:22 PST 2024
================
@@ -53,22 +53,49 @@ struct ConstrainedVectorConvertToLLVMPattern
}
};
+template <typename SourceOp, typename TargetOp,
+ template <typename, typename> typename AttrConvert =
+ AttrConvertPassThrough>
+struct DenormalOpConversionToLLVMPattern
+ : public VectorConvertToLLVMPattern<SourceOp, TargetOp, AttrConvert> {
+ using VectorConvertToLLVMPattern<SourceOp, TargetOp,
+ AttrConvert>::VectorConvertToLLVMPattern;
+
+ LogicalResult
+ matchAndRewrite(SourceOp op, typename SourceOp::Adaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ // TODO: Here, we need a legalization step. LLVM provides a function-level
+ // attribute for denormal; here, we need to move this information from the
+ // operation to the function, making sure all the operations in the same
+ // function are consistent.
+ if (op.getDenormalModeAttr().getValue() != arith::DenormalMode::ieee)
+ return rewriter.notifyMatchFailure(
+ op, "only ieee denormal mode is supported at the moment");
+
+ StringRef arithDenormalAttrName = SourceOp::getDenormalModeAttrName();
+ op->removeAttr(arithDenormalAttrName);
+ return VectorConvertToLLVMPattern<SourceOp, TargetOp,
+ AttrConvert>::matchAndRewrite(op, adaptor,
+ rewriter);
----------------
chelini wrote:
In this PR, we bail out if a non-default denormal mode is specified (default is ieee). We then remove it from the operation since we do not have a mapping to LLVM yet. The next step would be to add an LLVM attribute to model denormals and implement the legalization step mentioned in the TODOs.
https://github.com/llvm/llvm-project/pull/112700
More information about the Mlir-commits
mailing list