diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp index 4b5e055b5168..e2b41d027955 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp @@ -32,6 +32,7 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" +#include "mlir/Support/LogicalResult.h" #include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h" @@ -208,6 +209,18 @@ class CIRCosOpLowering : public mlir::OpConversionPattern { } }; +class CIRSinOpLowering : public mlir::OpConversionPattern { +public: + using mlir::OpConversionPattern::OpConversionPattern; + + mlir::LogicalResult + matchAndRewrite(mlir::cir::SinOp op, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override { + rewriter.replaceOpWithNewOp(op, adaptor.getSrc()); + return mlir::LogicalResult::success(); + } +}; + class CIRConstantOpLowering : public mlir::OpConversionPattern { public: @@ -987,14 +1000,14 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns, mlir::TypeConverter &converter) { patterns.add(patterns.getContext()); - patterns - .add( - converter, patterns.getContext()); + patterns.add(converter, + patterns.getContext()); } static mlir::TypeConverter prepareTypeConverter() { diff --git a/clang/test/CIR/Lowering/ThroughMLIR/sin.cir b/clang/test/CIR/Lowering/ThroughMLIR/sin.cir new file mode 100644 index 000000000000..c433b52e105c --- /dev/null +++ b/clang/test/CIR/Lowering/ThroughMLIR/sin.cir @@ -0,0 +1,30 @@ +// RUN: cir-opt %s -cir-to-mlir -o %t.mlir +// RUN: FileCheck %s --input-file %t.mlir + +module { + cir.func @foo() { + %1 = cir.const #cir.fp<1.0> : !cir.float + %2 = cir.const #cir.fp<1.0> : !cir.double + %3 = cir.const #cir.fp<1.0> : !cir.long_double + %4 = cir.const #cir.fp<1.0> : !cir.long_double + %5 = cir.sin %1 : !cir.float + %6 = cir.sin %2 : !cir.double + %7 = cir.sin %3 : !cir.long_double + %8 = cir.sin %4 : !cir.long_double + cir.return + } +} + +// CHECK: module { +// CHECK-NEXT: func.func @foo() { +// CHECK-NEXT: %[[C0:.+]] = arith.constant 1.000000e+00 : f32 +// CHECK-NEXT: %[[C1:.+]] = arith.constant 1.000000e+00 : f64 +// CHECK-NEXT: %[[C2:.+]] = arith.constant 1.000000e+00 : f80 +// CHECK-NEXT: %[[C3:.+]] = arith.constant 1.000000e+00 : f64 +// CHECK-NEXT: %{{.+}} = math.sin %[[C0]] : f32 +// CHECK-NEXT: %{{.+}} = math.sin %[[C1]] : f64 +// CHECK-NEXT: %{{.+}} = math.sin %[[C2]] : f80 +// CHECK-NEXT: %{{.+}} = math.sin %[[C3]] : f64 +// CHECK-NEXT: return +// CHECK-NEXT: } +// CHECK-NEXT: }