[clang] [CIR][NFC] Group related "creation" helpers + add comments (PR #180921)

Andrzej WarzyƄski via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 11 06:04:59 PST 2026


https://github.com/banach-space updated https://github.com/llvm/llvm-project/pull/180921

>From 0703c8d1d0cef1d0bde5dd49cdc2d659e4d4a6bb Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Wed, 11 Feb 2026 11:27:17 +0000
Subject: [PATCH 1/2] [CIR][NFC] Group related "creation" helpers + add
 comments

---
 clang/lib/CIR/CodeGen/CIRGenBuilder.h | 69 +++++++++++++++++----------
 1 file changed, 45 insertions(+), 24 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index c262f5dc3d812..4e2c7ae798b89 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -362,6 +362,16 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return getConstantInt(loc, getUInt64Ty(), c);
   }
 
+  /// Create constant nullptr for pointer-to-data-member type ty.
+  cir::ConstantOp getNullDataMemberPtr(cir::DataMemberType ty,
+                                       mlir::Location loc) {
+    return cir::ConstantOp::create(*this, loc, getNullDataMemberAttr(ty));
+  }
+
+  cir::ConstantOp getNullMethodPtr(cir::MethodType ty, mlir::Location loc) {
+    return cir::ConstantOp::create(*this, loc, getNullMethodAttr(ty));
+  }
+
   //
   // UnaryOp creation helpers
   // -------------------------
@@ -391,30 +401,10 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
                                 cir::UnaryOpKind::Minus, value);
   }
 
-  cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src,
-                                   cir::FPClassTest flags) {
-    return cir::IsFPClassOp::create(*this, loc, src, flags);
-  }
-
-  /// Create constant nullptr for pointer-to-data-member type ty.
-  cir::ConstantOp getNullDataMemberPtr(cir::DataMemberType ty,
-                                       mlir::Location loc) {
-    return cir::ConstantOp::create(*this, loc, getNullDataMemberAttr(ty));
-  }
-
-  cir::ConstantOp getNullMethodPtr(cir::MethodType ty, mlir::Location loc) {
-    return cir::ConstantOp::create(*this, loc, getNullMethodAttr(ty));
-  }
-
-  // TODO: split this to createFPExt/createFPTrunc when we have dedicated cast
-  // operations.
-  mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType) {
-    assert(!cir::MissingFeatures::fpConstraints());
-
-    return cir::CastOp::create(*this, v.getLoc(), destType,
-                               cir::CastKind::floating, v);
-  }
-
+  //
+  // BinaryOp creation helpers
+  // -------------------------
+  //
   mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
     assert(!cir::MissingFeatures::metaDataNode());
     assert(!cir::MissingFeatures::fpConstraints());
@@ -446,6 +436,20 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return cir::BinOp::create(*this, loc, cir::BinOpKind::Div, lhs, rhs);
   }
 
+  //
+  // CastOp creation helpers
+  // -------------------------
+  //
+
+  // TODO: split this to createFPExt/createFPTrunc when we have dedicated cast
+  // operations.
+  mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType) {
+    assert(!cir::MissingFeatures::fpConstraints());
+
+    return cir::CastOp::create(*this, v.getLoc(), destType,
+                               cir::CastKind::floating, v);
+  }
+
   mlir::Value createDynCast(mlir::Location loc, mlir::Value src,
                             cir::PointerType destType, bool isRefCast,
                             cir::DynamicCastInfoAttr info) {
@@ -465,6 +469,10 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
         cir::DynamicCastInfoAttr{}, vtableUseRelativeLayout);
   }
 
+  //
+  // Address creation helpers
+  // -------------------------
+  //
   Address createBaseClassAddr(mlir::Location loc, Address addr,
                               mlir::Type destType, unsigned offset,
                               bool assumeNotNull) {
@@ -491,6 +499,10 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return Address(derivedAddr, destType, addr.getAlignment());
   }
 
+  //
+  // Virtual Address creation helpers
+  // --------------------------------
+  //
   mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy,
                                  mlir::Value addr, uint64_t offset) {
     return cir::VTTAddrPointOp::create(*this, loc, retTy,
@@ -503,6 +515,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
                                        offset);
   }
 
+  //
+  // Other creation helpers
+  // ----------------------
+  //
+  cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src,
+                                   cir::FPClassTest flags) {
+    return cir::IsFPClassOp::create(*this, loc, src, flags);
+  }
+
   /// Cast the element type of the given address to a different type,
   /// preserving information like the alignment.
   Address createElementBitCast(mlir::Location loc, Address addr,

>From 22c93313d77c42df5e9d4cec184308d6908e1ec0 Mon Sep 17 00:00:00 2001
From: Andrzej Warzynski <andrzej.warzynski at arm.com>
Date: Wed, 11 Feb 2026 14:04:26 +0000
Subject: [PATCH 2/2] Align comments with LLVM style

---
 clang/lib/CIR/CodeGen/CIRGenBuilder.h | 35 +++++++++++----------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index 4e2c7ae798b89..5cb40ccf6704a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -345,10 +345,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return getType<cir::RecordType>(members, packed, padded, kind);
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // Constant creation helpers
-  // -------------------------
-  //
+  //===--------------------------------------------------------------------===//
   cir::ConstantOp getSInt32(int32_t c, mlir::Location loc) {
     return getConstantInt(loc, getSInt32Ty(), c);
   }
@@ -372,10 +371,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return cir::ConstantOp::create(*this, loc, getNullMethodAttr(ty));
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // UnaryOp creation helpers
-  // -------------------------
-  //
+  //===--------------------------------------------------------------------===//
   mlir::Value createNeg(mlir::Value value) {
 
     if (auto intTy = mlir::dyn_cast<cir::IntType>(value.getType())) {
@@ -401,10 +399,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
                                 cir::UnaryOpKind::Minus, value);
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // BinaryOp creation helpers
-  // -------------------------
-  //
+  //===--------------------------------------------------------------------===//
   mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
     assert(!cir::MissingFeatures::metaDataNode());
     assert(!cir::MissingFeatures::fpConstraints());
@@ -436,10 +433,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return cir::BinOp::create(*this, loc, cir::BinOpKind::Div, lhs, rhs);
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // CastOp creation helpers
-  // -------------------------
-  //
+  //===--------------------------------------------------------------------===//
 
   // TODO: split this to createFPExt/createFPTrunc when we have dedicated cast
   // operations.
@@ -469,10 +465,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
         cir::DynamicCastInfoAttr{}, vtableUseRelativeLayout);
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // Address creation helpers
-  // -------------------------
-  //
+  //===--------------------------------------------------------------------===//
   Address createBaseClassAddr(mlir::Location loc, Address addr,
                               mlir::Type destType, unsigned offset,
                               bool assumeNotNull) {
@@ -499,10 +494,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
     return Address(derivedAddr, destType, addr.getAlignment());
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // Virtual Address creation helpers
-  // --------------------------------
-  //
+  //===--------------------------------------------------------------------===//
   mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy,
                                  mlir::Value addr, uint64_t offset) {
     return cir::VTTAddrPointOp::create(*this, loc, retTy,
@@ -515,10 +509,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
                                        offset);
   }
 
-  //
+  //===--------------------------------------------------------------------===//
   // Other creation helpers
-  // ----------------------
-  //
+  //===--------------------------------------------------------------------===//
   cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src,
                                    cir::FPClassTest flags) {
     return cir::IsFPClassOp::create(*this, loc, src, flags);



More information about the cfe-commits mailing list