[clang] [CIR] Add support for array constructors (PR #149142)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 11:02:54 PDT 2025
================
@@ -22,15 +24,97 @@ struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
void runOnOperation() override;
void runOnOp(Operation *op);
+ void lowerArrayCtor(ArrayCtor op);
};
} // namespace
-void LoweringPreparePass::runOnOp(Operation *op) {}
+void LoweringPreparePass::runOnOp(Operation *op) {
+ if (auto arrayCtor = dyn_cast<ArrayCtor>(op)) {
+ lowerArrayCtor(arrayCtor);
+ }
+}
+
+static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder,
+ mlir::Operation *op, mlir::Type eltTy,
+ mlir::Value arrayAddr,
+ uint64_t arrayLen) {
+ // Generate loop to call into ctor/dtor for every element.
+ Location loc = op->getLoc();
+
+ // TODO: instead of fixed integer size, create alias for PtrDiffTy and unify
+ // with CIRGen stuff.
+ auto ptrDiffTy =
+ cir::IntType::get(builder.getContext(), 64, /*isSigned=*/false);
+ auto numArrayElementsConst = builder.create<cir::ConstantOp>(
+ loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, arrayLen));
+
+ auto begin = builder.create<cir::CastOp>(
+ loc, eltTy, cir::CastKind::array_to_ptrdecay, arrayAddr);
+ mlir::Value end = builder.create<cir::PtrStrideOp>(loc, eltTy, begin,
+ numArrayElementsConst);
+
+ mlir::Value tmpAddr = builder.createAlloca(
----------------
andykaylor wrote:
As we discussed, I think this is OK as it is.
https://github.com/llvm/llvm-project/pull/149142
More information about the cfe-commits
mailing list