diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index d9f0d4feb7cf..b771b80aa453 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -135,14 +135,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::TypedAttr getZeroInitAttr(mlir::Type ty) { if (mlir::isa(ty)) return cir::IntAttr::get(ty, 0); - if (auto fltType = mlir::dyn_cast(ty)) - return cir::FPAttr::getZero(fltType); - if (auto fltType = mlir::dyn_cast(ty)) - return cir::FPAttr::getZero(fltType); - if (auto fltType = mlir::dyn_cast(ty)) - return cir::FPAttr::getZero(fltType); - if (auto fltType = mlir::dyn_cast(ty)) - return cir::FPAttr::getZero(fltType); + if (cir::isAnyFloatingPointType(ty)) + return cir::FPAttr::getZero(ty); if (auto complexType = mlir::dyn_cast(ty)) return getZeroAttr(complexType); if (auto arrTy = mlir::dyn_cast(ty)) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 769542fe9411..cb00961ad07e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -498,6 +498,8 @@ mlir::Type CIRGenTypes::convertType(QualType T) { ResultType = Builder.getLongDoubleTy(astContext.getFloatTypeSemantics(T)); break; case BuiltinType::Float128: + ResultType = CGM.FP128Ty; + break; case BuiltinType::Ibm128: // FIXME: look at astContext.getFloatTypeSemantics(T) and getTypeForFormat // on LLVM codegen. diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 8c739721f0d3..71dd1ef771b2 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -705,7 +705,7 @@ LongDoubleType::verify(function_ref emitError, bool cir::isAnyFloatingPointType(mlir::Type t) { return isa(t); + cir::FP80Type, cir::BF16Type, cir::FP16Type, cir::FP128Type>(t); } bool cir::isScalarType(mlir::Type ty) { diff --git a/clang/test/CIR/global-var-simple.cpp b/clang/test/CIR/global-var-simple.cpp index 9c10deab2a02..cfe446f34378 100644 --- a/clang/test/CIR/global-var-simple.cpp +++ b/clang/test/CIR/global-var-simple.cpp @@ -58,3 +58,21 @@ _BitInt(20) sb20; unsigned _BitInt(48) ub48; // CHECK: external @ub48 = #cir.int<0> : !u48i + +_Float16 f16; +// CHECK: cir.global external @f16 = #cir.fp<0.000000e+00> : !cir.f16 + +__bf16 bf16; +// CHECK: cir.global external @bf16 = #cir.fp<0.000000e+00> : !cir.bf16 + +float f; +// CHECK: cir.global external @f = #cir.fp<0.000000e+00> : !cir.float + +double d = 1.25; +// CHECK: cir.global external @d = #cir.fp<1.250000e+00> : !cir.double + +long double ld; +// CHECK: cir.global external @ld = #cir.fp<0.000000e+00> : !cir.long_double + +__float128 f128; +// CHECK: cir.global external @f128 = #cir.fp<0.000000e+00> : !cir.f128