Skip to content

Commit c861519

Browse files
ayokunle321lanza
authored andcommitted
[CIR][ThroughMLIR] Add ATanOp Lowering (#1528)
Adds implementation for ATanOp's lowering ThroughMLIR.
1 parent ea4458a commit c861519

File tree

2 files changed

+59
-16
lines changed

2 files changed

+59
-16
lines changed

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ class CIRStoreOpLowering : public mlir::OpConversionPattern<cir::StoreOp> {
279279
}
280280
};
281281

282+
class CIRATanOpLowering : public mlir::OpConversionPattern<cir::ATanOp> {
283+
public:
284+
using OpConversionPattern<cir::ATanOp>::OpConversionPattern;
285+
286+
mlir::LogicalResult
287+
matchAndRewrite(cir::ATanOp op, OpAdaptor adaptor,
288+
mlir::ConversionPatternRewriter &rewriter) const override {
289+
rewriter.replaceOpWithNewOp<mlir::math::AtanOp>(op, adaptor.getSrc());
290+
return mlir::LogicalResult::success();
291+
}
292+
};
293+
282294
class CIRCosOpLowering : public mlir::OpConversionPattern<cir::CosOp> {
283295
public:
284296
using OpConversionPattern<cir::CosOp>::OpConversionPattern;
@@ -1356,22 +1368,23 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
13561368
mlir::TypeConverter &converter) {
13571369
patterns.add<CIRReturnLowering, CIRBrOpLowering>(patterns.getContext());
13581370

1359-
patterns.add<
1360-
CIRCmpOpLowering, CIRCallOpLowering, CIRUnaryOpLowering, CIRBinOpLowering,
1361-
CIRLoadOpLowering, CIRConstantOpLowering, CIRStoreOpLowering,
1362-
CIRAllocaOpLowering, CIRFuncOpLowering, CIRScopeOpLowering,
1363-
CIRBrCondOpLowering, CIRTernaryOpLowering, CIRYieldOpLowering,
1364-
CIRCosOpLowering, CIRGlobalOpLowering, CIRGetGlobalOpLowering,
1365-
CIRCastOpLowering, CIRPtrStrideOpLowering, CIRSqrtOpLowering,
1366-
CIRCeilOpLowering, CIRExp2OpLowering, CIRExpOpLowering, CIRFAbsOpLowering,
1367-
CIRAbsOpLowering, CIRFloorOpLowering, CIRLog10OpLowering,
1368-
CIRLog2OpLowering, CIRLogOpLowering, CIRRoundOpLowering,
1369-
CIRPtrStrideOpLowering, CIRSinOpLowering, CIRShiftOpLowering,
1370-
CIRBitClzOpLowering, CIRBitCtzOpLowering, CIRBitPopcountOpLowering,
1371-
CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering,
1372-
CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering,
1373-
CIRVectorExtractLowering, CIRVectorCmpOpLowering>(converter,
1374-
patterns.getContext());
1371+
patterns
1372+
.add<CIRATanOpLowering, CIRCmpOpLowering, CIRCallOpLowering,
1373+
CIRUnaryOpLowering, CIRBinOpLowering, CIRLoadOpLowering,
1374+
CIRConstantOpLowering, CIRStoreOpLowering, CIRAllocaOpLowering,
1375+
CIRFuncOpLowering, CIRScopeOpLowering, CIRBrCondOpLowering,
1376+
CIRTernaryOpLowering, CIRYieldOpLowering, CIRCosOpLowering,
1377+
CIRGlobalOpLowering, CIRGetGlobalOpLowering, CIRCastOpLowering,
1378+
CIRPtrStrideOpLowering, CIRSqrtOpLowering, CIRCeilOpLowering,
1379+
CIRExp2OpLowering, CIRExpOpLowering, CIRFAbsOpLowering,
1380+
CIRAbsOpLowering, CIRFloorOpLowering, CIRLog10OpLowering,
1381+
CIRLog2OpLowering, CIRLogOpLowering, CIRRoundOpLowering,
1382+
CIRPtrStrideOpLowering, CIRSinOpLowering, CIRShiftOpLowering,
1383+
CIRBitClzOpLowering, CIRBitCtzOpLowering, CIRBitPopcountOpLowering,
1384+
CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering,
1385+
CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering,
1386+
CIRVectorExtractLowering, CIRVectorCmpOpLowering>(
1387+
converter, patterns.getContext());
13751388
}
13761389

13771390
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<1.0> : !cir.double
8+
%3 = cir.const #cir.fp<1.0> : !cir.long_double<!cir.f80>
9+
%4 = cir.const #cir.fp<1.0> : !cir.long_double<!cir.double>
10+
%5 = cir.atan %1 : !cir.float
11+
%6 = cir.atan %2 : !cir.double
12+
%7 = cir.atan %3 : !cir.long_double<!cir.f80>
13+
%8 = cir.atan %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 1.000000e+00 : f64
22+
// CHECK-NEXT: %[[C2:.+]] = arith.constant 1.000000e+00 : f80
23+
// CHECK-NEXT: %[[C3:.+]] = arith.constant 1.000000e+00 : f64
24+
// CHECK-NEXT: %{{.+}} = math.atan %[[C0]] : f32
25+
// CHECK-NEXT: %{{.+}} = math.atan %[[C1]] : f64
26+
// CHECK-NEXT: %{{.+}} = math.atan %[[C2]] : f80
27+
// CHECK-NEXT: %{{.+}} = math.atan %[[C3]] : f64
28+
// CHECK-NEXT: return
29+
// CHECK-NEXT: }
30+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)