Skip to content

Commit

Permalink
add helpfer function CIRGenBuilderTy::getConstFP
Browse files Browse the repository at this point in the history
  • Loading branch information
ghehg committed Sep 27, 2024
1 parent 47ac32d commit 6349523
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ mlir::cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
return create<mlir::cir::ConstantOp>(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<mlir::cir::SingleType, mlir::cir::DoubleType>(t)) &&
"expected mlir::cir::SingleType or mlir::cir::DoubleType");
return create<mlir::cir::ConstantOp>(loc, t,
getAttr<mlir::cir::FPAttr>(t, fpVal));
}

} // namespace cir
4 changes: 4 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mlir::cir::ConstantOp>(
getLoc(E->getExprLoc()), resTy,
builder.getAttr<mlir::cir::FPAttr>(resTy, Result.Val.getFloat())));
return RValue::get(builder.getConstFP(getLoc(E->getExprLoc()), resTy,
Result.Val.getFloat()));
}
}

Expand Down

0 comments on commit 6349523

Please sign in to comment.