Skip to content

Commit

Permalink
[CIR] Add MLIR lowering for f16, bf16, and f128 (#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancern authored Jan 7, 2025
1 parent d1bd77c commit 294eae2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,15 @@ static mlir::TypeConverter prepareTypeConverter() {
converter.addConversion([&](cir::LongDoubleType type) -> mlir::Type {
return converter.convertType(type.getUnderlying());
});
converter.addConversion([&](cir::FP128Type type) -> mlir::Type {
return mlir::FloatType::getF128(type.getContext());
});
converter.addConversion([&](cir::FP16Type type) -> mlir::Type {
return mlir::FloatType::getF16(type.getContext());
});
converter.addConversion([&](cir::BF16Type type) -> mlir::Type {
return mlir::FloatType::getBF16(type.getContext());
});
converter.addConversion([&](cir::ArrayType type) -> mlir::Type {
SmallVector<int64_t> shape;
mlir::Type curType = type;
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CIR/Lowering/ThroughMLIR/float.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: cir-opt %s -cir-to-mlir -o %t.mlir
// RUN: FileCheck %s --input-file %t.mlir

module {
cir.func @foo() {
%0 = cir.const #cir.fp<1.0> : !cir.float
%1 = cir.const #cir.fp<1.0> : !cir.double
%2 = cir.const #cir.fp<1.0> : !cir.long_double<!cir.f80>
%3 = cir.const #cir.fp<1.0> : !cir.f128
%4 = cir.const #cir.fp<1.0> : !cir.f16
%5 = cir.const #cir.fp<1.0> : !cir.bf16
cir.return
}

// CHECK-LABEL: @foo
// CHECK: %{{.+}} = arith.constant 1.000000e+00 : f32
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f64
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f80
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f128
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : f16
// CHECK-NEXT: %{{.+}} = arith.constant 1.000000e+00 : bf16
// CHECK: }
}

0 comments on commit 294eae2

Please sign in to comment.