Skip to content

Commit 6349523

Browse files
committed
add helpfer function CIRGenBuilderTy::getConstFP
1 parent 47ac32d commit 6349523

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ mlir::cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
6767
return create<mlir::cir::ConstantOp>(loc, intTy,
6868
mlir::cir::IntAttr::get(t, C));
6969
}
70+
71+
mlir::cir::ConstantOp CIRGenBuilderTy::getConstFP(mlir::Location loc,
72+
mlir::Type t,
73+
llvm::APFloat fpVal) {
74+
assert((mlir::isa<mlir::cir::SingleType, mlir::cir::DoubleType>(t)) &&
75+
"expected mlir::cir::SingleType or mlir::cir::DoubleType");
76+
return create<mlir::cir::ConstantOp>(loc, t,
77+
getAttr<mlir::cir::FPAttr>(t, fpVal));
78+
}
79+
7080
} // namespace cir

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
536536

537537
mlir::cir::ConstantOp getConstInt(mlir::Location loc, mlir::Type t,
538538
uint64_t C);
539+
540+
mlir::cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t,
541+
llvm::APFloat fpVal);
542+
539543
/// Create constant nullptr for pointer-to-data-member type ty.
540544
mlir::cir::ConstantOp getNullDataMemberPtr(mlir::cir::DataMemberType ty,
541545
mlir::Location loc) {

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,8 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
320320
// it is hard to imagine a builtin function evaluates to
321321
// a value that over/underflows its own defined type.
322322
mlir::Type resTy = getCIRType(E->getType());
323-
return RValue::get(builder.create<mlir::cir::ConstantOp>(
324-
getLoc(E->getExprLoc()), resTy,
325-
builder.getAttr<mlir::cir::FPAttr>(resTy, Result.Val.getFloat())));
323+
return RValue::get(builder.getConstFP(getLoc(E->getExprLoc()), resTy,
324+
Result.Val.getFloat()));
326325
}
327326
}
328327

0 commit comments

Comments
 (0)