Skip to content

Commit f769f13

Browse files
ayokunle321lanza
authored andcommitted
[CIR][ThroughMLIR] Add ASinOp Lowering (llvm#1530)
Adds implementation for ASinOp's lowering ThroughMLIR.
1 parent 8715197 commit f769f13

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
@@ -495,6 +495,18 @@ class CIRSinOpLowering : public mlir::OpConversionPattern<cir::SinOp> {
495495
}
496496
};
497497

498+
class CIRASinOpLowering : public mlir::OpConversionPattern<cir::ASinOp> {
499+
public:
500+
using mlir::OpConversionPattern<cir::ASinOp>::OpConversionPattern;
501+
502+
mlir::LogicalResult
503+
matchAndRewrite(cir::ASinOp op, OpAdaptor adaptor,
504+
mlir::ConversionPatternRewriter &rewriter) const override {
505+
rewriter.replaceOpWithNewOp<mlir::math::AsinOp>(op, adaptor.getSrc());
506+
return mlir::LogicalResult::success();
507+
}
508+
};
509+
498510
template <typename CIROp, typename MLIROp>
499511
class CIRCountZerosBitOpLowering : public mlir::OpConversionPattern<CIROp> {
500512
public:
@@ -1422,8 +1434,8 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
14221434
CIRBitClzOpLowering, CIRBitCtzOpLowering, CIRBitPopcountOpLowering,
14231435
CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering,
14241436
CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering,
1425-
CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering>(
1426-
converter, patterns.getContext());
1437+
CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering,
1438+
CIRASinOpLowering>(converter, patterns.getContext());
14271439
}
14281440

14291441
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.asin %1 : !cir.float
11+
%6 = cir.asin %2 : !cir.double
12+
%7 = cir.asin %3 : !cir.long_double<!cir.f80>
13+
%8 = cir.asin %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.asin %[[C0]] : f32
25+
// CHECK-NEXT: %{{.+}} = math.asin %[[C1]] : f64
26+
// CHECK-NEXT: %{{.+}} = math.asin %[[C2]] : f80
27+
// CHECK-NEXT: %{{.+}} = math.asin %[[C3]] : f64
28+
// CHECK-NEXT: return
29+
// CHECK-NEXT: }
30+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)