Skip to content

Commit 294eae2

Browse files
authored
[CIR] Add MLIR lowering for f16, bf16, and f128 (#1264)
1 parent d1bd77c commit 294eae2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,15 @@ static mlir::TypeConverter prepareTypeConverter() {
14011401
converter.addConversion([&](cir::LongDoubleType type) -> mlir::Type {
14021402
return converter.convertType(type.getUnderlying());
14031403
});
1404+
converter.addConversion([&](cir::FP128Type type) -> mlir::Type {
1405+
return mlir::FloatType::getF128(type.getContext());
1406+
});
1407+
converter.addConversion([&](cir::FP16Type type) -> mlir::Type {
1408+
return mlir::FloatType::getF16(type.getContext());
1409+
});
1410+
converter.addConversion([&](cir::BF16Type type) -> mlir::Type {
1411+
return mlir::FloatType::getBF16(type.getContext());
1412+
});
14041413
converter.addConversion([&](cir::ArrayType type) -> mlir::Type {
14051414
SmallVector<int64_t> shape;
14061415
mlir::Type curType = type;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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<1.0> : !cir.double
8+
%2 = cir.const #cir.fp<1.0> : !cir.long_double<!cir.f80>
9+
%3 = cir.const #cir.fp<1.0> : !cir.f128
10+
%4 = cir.const #cir.fp<1.0> : !cir.f16
11+
%5 = cir.const #cir.fp<1.0> : !cir.bf16
12+
cir.return
13+
}
14+
15+
// CHECK-LABEL: @foo
16+
// CHECK: %{{.+}} = arith.constant 1.000000e+00 : f32
17+
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f64
18+
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f80
19+
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f128
20+
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f16
21+
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : bf16
22+
// CHECK: }
23+
}

0 commit comments

Comments
 (0)