[clang] [CIR] Pointer and vptr width from a CIR-native data-layout entry (PR #204185)
Akshay K via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 3 08:54:28 PDT 2026
================
@@ -42,7 +45,25 @@ static void setMLIRDataLayout(mlir::ModuleOp &mod, const llvm::DataLayout &dl) {
mlir::MLIRContext *mlirContext = mod.getContext();
mlir::DataLayoutSpecInterface dlSpec =
mlir::translateDataLayout(dl, mlirContext);
- mod->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, dlSpec);
+
+ // Record cir.ptr size/alignment as a #ptr.spec entry keyed on cir.ptr.
+ // TODO(cir): only the default address space is recorded.
+ assert(!cir::MissingFeatures::dataLayoutPtrHandlingBasedOnLangAS());
+ constexpr unsigned kBitsInByte = 8;
+ unsigned ptrSizeBits = dl.getPointerSizeInBits(/*AS=*/0);
+ unsigned ptrAbiBits =
+ dl.getPointerABIAlignment(/*AS=*/0).value() * kBitsInByte;
+ unsigned ptrPrefBits =
+ dl.getPointerPrefAlignment(/*AS=*/0).value() * kBitsInByte;
+ auto ptrKey = cir::PointerType::get(cir::VoidType::get(mlirContext));
+ auto ptrSpec = mlir::ptr::SpecAttr::get(mlirContext, ptrSizeBits, ptrAbiBits,
----------------
kumarak wrote:
Pushed a commit to have CIR native `PtrSpecAttr` mirroring `ptr::SpecAttr` that will hold the `PointerType` specification. Also, move the `setMLIRDatalayout` to use it for both `cir-translate` and `-fclagir` path.
https://github.com/llvm/llvm-project/pull/204185
More information about the cfe-commits
mailing list