diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp index 13ec20d8eda2..f20ee528f36d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp @@ -67,4 +67,14 @@ mlir::cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, return create(loc, intTy, mlir::cir::IntAttr::get(t, C)); } + +mlir::cir::ConstantOp CIRGenBuilderTy::getConstFP(mlir::Location loc, + mlir::Type t, + llvm::APFloat fpVal) { + assert((mlir::isa(t)) && + "expected mlir::cir::SingleType or mlir::cir::DoubleType"); + return create(loc, t, + getAttr(t, fpVal)); +} + } // namespace cir diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index a02cdf26ee4d..836a42b21ebd 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -536,6 +536,10 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy { mlir::cir::ConstantOp getConstInt(mlir::Location loc, mlir::Type t, uint64_t C); + + mlir::cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t, + llvm::APFloat fpVal); + /// Create constant nullptr for pointer-to-data-member type ty. mlir::cir::ConstantOp getNullDataMemberPtr(mlir::cir::DataMemberType ty, mlir::Location loc) { diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 801332583a86..297371ac65e4 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -320,9 +320,8 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, // it is hard to imagine a builtin function evaluates to // a value that over/underflows its own defined type. mlir::Type resTy = getCIRType(E->getType()); - return RValue::get(builder.create( - getLoc(E->getExprLoc()), resTy, - builder.getAttr(resTy, Result.Val.getFloat()))); + return RValue::get(builder.getConstFP(getLoc(E->getExprLoc()), resTy, + Result.Val.getFloat())); } }