================ @@ -67,6 +67,40 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return create<cir::ConstantOp>(loc, attr.getType(), attr); } + mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) { + assert(mlir::isa<cir::PointerType>(t) && "expected cir.ptr"); + return getConstPtrAttr(t, 0); + } + + mlir::TypedAttr getZeroAttr(mlir::Type t) { + return cir::ZeroAttr::get(getContext(), t); + } + + mlir::TypedAttr getZeroInitAttr(mlir::Type ty) { + if (mlir::isa<cir::IntType>(ty)) + return cir::IntAttr::get(ty, 0); + if (auto fltType = mlir::dyn_cast<cir::SingleType>(ty)) + return cir::FPAttr::getZero(fltType); + if (auto fltType = mlir::dyn_cast<cir::DoubleType>(ty)) + return cir::FPAttr::getZero(fltType); + if (auto fltType = mlir::dyn_cast<cir::LongDoubleType>(ty)) + return cir::FPAttr::getZero(fltType); + if (auto fltType = mlir::dyn_cast<cir::FP16Type>(ty)) + return cir::FPAttr::getZero(fltType); + if (auto fltType = mlir::dyn_cast<cir::FP128Type>(ty)) + return cir::FPAttr::getZero(fltType); + if (auto fltType = mlir::dyn_cast<cir::BF16Type>(ty)) + return cir::FPAttr::getZero(fltType); + if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty)) + return getZeroAttr(arrTy); + if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty)) + return getConstNullPtrAttr(ptrTy); + if (mlir::isa<cir::BoolType>(ty)) { + return getCIRBoolAttr(false); + } + llvm_unreachable("Zero initializer for given type is NYI"); + } ---------------- bcardosolopes wrote:
Seems like all these 3 functions are a repetition from https://github.com/llvm/llvm-project/pull/132974, this is a bit confusing and requiring reviewing the same content more than once - might be better to wait until the dep lands or work on something without dependency https://github.com/llvm/llvm-project/pull/133100 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits