[clang] [CIR] Streamline creation of mlir::IntegerAttrs using mlir::Builder (PR #141830)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Thu May 29 03:19:06 PDT 2025


================
@@ -428,13 +422,28 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
     return OpBuilder::InsertPoint(block, block->begin());
   };
 
-  mlir::IntegerAttr getSizeFromCharUnits(mlir::MLIRContext *ctx,
-                                         clang::CharUnits size) {
-    // Note that mlir::IntegerType is used instead of cir::IntType here
-    // because we don't need sign information for this to be useful, so keep
-    // it simple.
-    return mlir::IntegerAttr::get(mlir::IntegerType::get(ctx, 64),
-                                  size.getQuantity());
+  //
+  // Alignement and size helpers
+  //
+
+  // Note that mlir::IntegerType is used instead of cir::IntType here because we
+  // don't need sign information for these to be useful, so keep it simple.
+
+  // Fot 0 alignment, return an empty attribute.
+  mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment) {
+    return getAlignmentAttr(alignment.getQuantity());
+  }
+
+  mlir::IntegerAttr getAlignmentAttr(llvm::Align alignment) {
+    return getAlignmentAttr(alignment.value());
+  }
+
+  mlir::IntegerAttr getAlignmentAttr(int64_t alignment) {
----------------
xlauko wrote:

It was meant for entire overload set, thats why I put before all. 

https://github.com/llvm/llvm-project/pull/141830


More information about the cfe-commits mailing list