[clang] [CIR] Add support for array constructors (PR #149142)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 17 05:01:52 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));
----------------
xlauko wrote:
```suggestion
cir::ConstantOp numArrayElementsConst = builder.getUnsignedInt(loc, 64, arrayLen);
```
https://github.com/llvm/llvm-project/pull/149142
More information about the cfe-commits
mailing list