Skip to content

Commit edc35e4

Browse files
goxullanza
authored andcommitted
[CIR][ThroughMLIR] Add TanOp Lowering (llvm#1540)
Adds implementation for TanOp's lowering via ThroughMLIR.
1 parent f024937 commit edc35e4

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
@@ -316,6 +316,18 @@ class CIRCosOpLowering : public mlir::OpConversionPattern<cir::CosOp> {
316316
}
317317
};
318318

319+
class CIRTanOpLowering : public mlir::OpConversionPattern<cir::TanOp> {
320+
public:
321+
using OpConversionPattern<cir::TanOp>::OpConversionPattern;
322+
323+
mlir::LogicalResult
324+
matchAndRewrite(cir::TanOp op, OpAdaptor adaptor,
325+
mlir::ConversionPatternRewriter &rewriter) const override {
326+
rewriter.replaceOpWithNewOp<mlir::math::TanOp>(op, adaptor.getSrc());
327+
return mlir::LogicalResult::success();
328+
}
329+
};
330+
319331
class CIRSqrtOpLowering : public mlir::OpConversionPattern<cir::SqrtOp> {
320332
public:
321333
using mlir::OpConversionPattern<cir::SqrtOp>::OpConversionPattern;
@@ -1446,8 +1458,8 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
14461458
CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering,
14471459
CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering,
14481460
CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering,
1449-
CIRASinOpLowering, CIRUnreachableOpLowering>(converter,
1450-
patterns.getContext());
1461+
CIRASinOpLowering, CIRUnreachableOpLowering, CIRTanOpLowering>(
1462+
converter, patterns.getContext());
14511463
}
14521464

14531465
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)