[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 13:16:07 PDT 2025
================
@@ -78,6 +79,67 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
return create<cir::StoreOp>(loc, val, dst);
}
+ //===--------------------------------------------------------------------===//
+ // Cast/Conversion Operators
+ //===--------------------------------------------------------------------===//
+
+ mlir::Value createCast(mlir::Location loc, cir::CastKind kind,
+ mlir::Value src, mlir::Type newTy) {
+ if (newTy == src.getType())
+ return src;
+ return create<cir::CastOp>(loc, newTy, kind, src);
+ }
+
+ mlir::Value createCast(cir::CastKind kind, mlir::Value src,
+ mlir::Type newTy) {
+ if (newTy == src.getType())
+ return src;
+ return createCast(src.getLoc(), kind, src, newTy);
+ }
+
+ mlir::Value createIntCast(mlir::Value src, mlir::Type newTy) {
+ return createCast(cir::CastKind::integral, src, newTy);
+ }
+
+ mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy) {
+ return createCast(cir::CastKind::int_to_ptr, src, newTy);
+ }
+
+ mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {
+ return createCast(cir::CastKind::ptr_to_int, src, newTy);
+ }
+
+ mlir::Value createPtrToBoolCast(mlir::Value v) {
+ return createCast(cir::CastKind::ptr_to_bool, v, getBoolTy());
+ }
+
+ mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy) {
+ return createCast(cir::CastKind::bool_to_int, src, newTy);
+ }
+
+ mlir::Value createBitcast(mlir::Value src, mlir::Type newTy) {
+ return createCast(cir::CastKind::bitcast, src, newTy);
+ }
+
+ mlir::Value createBitcast(mlir::Location loc, mlir::Value src,
+ mlir::Type newTy) {
+ return createCast(loc, cir::CastKind::bitcast, src, newTy);
+ }
+
+ mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy) {
+ assert(mlir::isa<cir::PointerType>(src.getType()) && "expected ptr src");
+ return createBitcast(src, getPointerTo(newPointeeTy));
+ }
+
+ mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src,
----------------
andykaylor wrote:
I'm guessing these aren't used either. I don't think we have upstreamed any address space support, have we?
https://github.com/llvm/llvm-project/pull/130690
More information about the cfe-commits
mailing list