Skip to content

Commit df158bf

Browse files
authored
[CIR][ThroughMLIR] Add TanOp Lowering (#1540)
Adds implementation for TanOp's lowering via ThroughMLIR.
1 parent 8bcd07c commit df158bf

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ class CIRCosOpLowering : public mlir::OpConversionPattern<cir::CosOp> {
311311
}
312312
};
313313

314+
class CIRTanOpLowering : public mlir::OpConversionPattern<cir::TanOp> {
315+
public:
316+
using OpConversionPattern<cir::TanOp>::OpConversionPattern;
317+
318+
mlir::LogicalResult
319+
matchAndRewrite(cir::TanOp op, OpAdaptor adaptor,
320+
mlir::ConversionPatternRewriter &rewriter) const override {
321+
rewriter.replaceOpWithNewOp<mlir::math::TanOp>(op, adaptor.getSrc());
322+
return mlir::LogicalResult::success();
323+
}
324+
};
325+
314326
class CIRSqrtOpLowering : public mlir::OpConversionPattern<cir::SqrtOp> {
315327
public:
316328
using mlir::OpConversionPattern<cir::SqrtOp>::OpConversionPattern;
@@ -1418,8 +1430,8 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
14181430
CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering,
14191431
CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering,
14201432
CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering,
1421-
CIRASinOpLowering, CIRUnreachableOpLowering>(converter,
1422-
patterns.getContext());
1433+
CIRASinOpLowering, CIRUnreachableOpLowering, CIRTanOpLowering>(
1434+
converter, patterns.getContext());
14231435
}
14241436

14251437
static mlir::TypeConverter prepareTypeConverter() {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: cir-opt %s -cir-to-mlir -o %t.mlir
2+
// RUN: FileCheck %s --input-file %t.mlir
3+
4+
module {
5+
cir.func @foo() {
6+
%1 = cir.const #cir.fp<1.0> : !cir.float
7+
%2 = cir.const #cir.fp<2.0> : !cir.double
8+
%3 = cir.const #cir.fp<3.0> : !cir.long_double<!cir.f80>
9+
%4 = cir.const #cir.fp<4.0> : !cir.long_double<!cir.double>
10+
%5 = cir.tan %1 : !cir.float
11+
%6 = cir.tan %2 : !cir.double
12+
%7 = cir.tan %3 : !cir.long_double<!cir.f80>
13+
%8 = cir.tan %4 : !cir.long_double<!cir.double>
14+
cir.return
15+
}
16+
}
17+
18+
// CHECK: module {
19+
// CHECK-NEXT: func.func @foo() {
20+
// CHECK-NEXT: %[[C0:.+]] = arith.constant 1.000000e+00 : f32
21+
// CHECK-NEXT: %[[C1:.+]] = arith.constant 2.000000e+00 : f64
22+
// CHECK-NEXT: %[[C2:.+]] = arith.constant 3.000000e+00 : f80
23+
// CHECK-NEXT: %[[C3:.+]] = arith.constant 4.000000e+00 : f64
24+
// CHECK-NEXT: %{{.+}} = math.tan %[[C0]] : f32
25+
// CHECK-NEXT: %{{.+}} = math.tan %[[C1]] : f64
26+
// CHECK-NEXT: %{{.+}} = math.tan %[[C2]] : f80
27+
// CHECK-NEXT: %{{.+}} = math.tan %[[C3]] : f64
28+
// CHECK-NEXT: return
29+
// CHECK-NEXT: }
30+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)