@@ -75,7 +75,11 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
7575 SmallVector<mlir::NamedAttribute> attributes;
7676
7777 if (init.has_value ()) {
78- if (auto intAttr = mlir::dyn_cast<cir::IntAttr>(init.value ())) {
78+ if (auto fltAttr = mlir::dyn_cast<cir::FPAttr>(init.value ())) {
79+ // Initializer is a constant floating-point number: convert to MLIR
80+ // builtin constant.
81+ init = rewriter.getFloatAttr (llvmType, fltAttr.getValue ());
82+ } else if (auto intAttr = mlir::dyn_cast<cir::IntAttr>(init.value ())) {
7983 // Initializer is a constant array: convert it to a compatible llvm init.
8084 init = rewriter.getIntegerAttr (llvmType, intAttr.getValue ());
8185 } else {
@@ -99,6 +103,27 @@ static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
99103 // LLVM doesn't work with signed types, so we drop the CIR signs here.
100104 return mlir::IntegerType::get (type.getContext (), type.getWidth ());
101105 });
106+ converter.addConversion ([&](cir::SingleType type) -> mlir::Type {
107+ return mlir::Float32Type::get (type.getContext ());
108+ });
109+ converter.addConversion ([&](cir::DoubleType type) -> mlir::Type {
110+ return mlir::Float64Type::get (type.getContext ());
111+ });
112+ converter.addConversion ([&](cir::FP80Type type) -> mlir::Type {
113+ return mlir::Float80Type::get (type.getContext ());
114+ });
115+ converter.addConversion ([&](cir::FP128Type type) -> mlir::Type {
116+ return mlir::Float128Type::get (type.getContext ());
117+ });
118+ converter.addConversion ([&](cir::LongDoubleType type) -> mlir::Type {
119+ return converter.convertType (type.getUnderlying ());
120+ });
121+ converter.addConversion ([&](cir::FP16Type type) -> mlir::Type {
122+ return mlir::Float16Type::get (type.getContext ());
123+ });
124+ converter.addConversion ([&](cir::BF16Type type) -> mlir::Type {
125+ return mlir::BFloat16Type::get (type.getContext ());
126+ });
102127}
103128
104129void ConvertCIRToLLVMPass::runOnOperation () {
0 commit comments