Skip to content

Commit 0fe2ade

Browse files
author
Gao Xiang
committed
lowering sin operation to mlir
1 parent f690ca9 commit 0fe2ade

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "mlir/IR/BuiltinTypes.h"
3333
#include "mlir/Pass/Pass.h"
3434
#include "mlir/Pass/PassManager.h"
35+
#include "mlir/Support/LogicalResult.h"
3536
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
3637
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
3738
#include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
@@ -153,6 +154,18 @@ class CIRCosOpLowering : public mlir::OpConversionPattern<mlir::cir::CosOp> {
153154
}
154155
};
155156

157+
class CIRSinOpLowering : public mlir::OpConversionPattern<mlir::cir::SinOp> {
158+
public:
159+
using mlir::OpConversionPattern<mlir::cir::SinOp>::OpConversionPattern;
160+
161+
mlir::LogicalResult
162+
matchAndRewrite(mlir::cir::SinOp op, OpAdaptor adaptor,
163+
mlir::ConversionPatternRewriter &rewriter) const override {
164+
rewriter.replaceOpWithNewOp<mlir::math::SinOp>(op, adaptor.getSrc());
165+
return mlir::LogicalResult::success();
166+
}
167+
};
168+
156169
class CIRConstantOpLowering
157170
: public mlir::OpConversionPattern<mlir::cir::ConstantOp> {
158171
public:
@@ -847,7 +860,7 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
847860
CIRStoreOpLowering, CIRAllocaOpLowering, CIRFuncOpLowering,
848861
CIRScopeOpLowering, CIRBrCondOpLowering, CIRTernaryOpLowering,
849862
CIRYieldOpLowering, CIRCosOpLowering, CIRGlobalOpLowering,
850-
CIRGetGlobalOpLowering, CIRCastOpLowering>(
863+
CIRGetGlobalOpLowering, CIRCastOpLowering, CIRSinOpLowering>(
851864
converter, patterns.getContext());
852865
}
853866

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

0 commit comments

Comments
 (0)