Skip to content

Commit 7ec6a86

Browse files
ayokunle321lanza
authored andcommitted
[CIR][ThroughMLIR] Add ACosOp Lowering (#1529)
Adds implementation for ACosOp's lowering ThroughMLIR.
1 parent dfef455 commit 7ec6a86

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

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

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

282+
class CIRACosOpLowering : public mlir::OpConversionPattern<cir::ACosOp> {
283+
public:
284+
using OpConversionPattern<cir::ACosOp>::OpConversionPattern;
285+
286+
mlir::LogicalResult
287+
matchAndRewrite(cir::ACosOp op, OpAdaptor adaptor,
288+
mlir::ConversionPatternRewriter &rewriter) const override {
289+
rewriter.replaceOpWithNewOp<mlir::math::AcosOp>(op, adaptor.getSrc());
290+
return mlir::LogicalResult::success();
291+
}
292+
};
293+
282294
class CIRATanOpLowering : public mlir::OpConversionPattern<cir::ATanOp> {
283295
public:
284296
using OpConversionPattern<cir::ATanOp>::OpConversionPattern;
@@ -1383,7 +1395,7 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
13831395
CIRBitClzOpLowering, CIRBitCtzOpLowering, CIRBitPopcountOpLowering,
13841396
CIRBitClrsbOpLowering, CIRBitFfsOpLowering, CIRBitParityOpLowering,
13851397
CIRIfOpLowering, CIRVectorCreateLowering, CIRVectorInsertLowering,
1386-
CIRVectorExtractLowering, CIRVectorCmpOpLowering>(
1398+
CIRVectorExtractLowering, CIRVectorCmpOpLowering, CIRACosOpLowering>(
13871399
converter, patterns.getContext());
13881400
}
13891401

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

0 commit comments

Comments
 (0)