[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 19 13:08:12 PDT 2025
================
@@ -228,6 +257,42 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::FPAttr fltAttr) {
loc, converter->convertType(fltAttr.getType()), fltAttr.getValue());
}
+// ConstArrayAttr visitor
+mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
+ mlir::Type llvmTy = converter->convertType(attr.getType());
+ mlir::Location loc = parentOp->getLoc();
+ mlir::Value result;
+
+ if (auto zeros = attr.getTrailingZerosNum()) {
+ mlir::Type arrayTy = attr.getType();
+ result = rewriter.create<mlir::LLVM::ZeroOp>(
+ loc, converter->convertType(arrayTy));
+ } else {
+ result = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
+ }
+
+ // Iteratively lower each constant element of the array.
+ if (auto arrayAttr = mlir::dyn_cast<mlir::ArrayAttr>(attr.getElts())) {
+ for (auto [idx, elt] : llvm::enumerate(arrayAttr)) {
+ mlir::DataLayout dataLayout(parentOp->getParentOfType<mlir::ModuleOp>());
+ mlir::Value init = visit(elt);
+ result =
+ rewriter.create<mlir::LLVM::InsertValueOp>(loc, result, init, idx);
+ }
+ } else {
+ llvm_unreachable("unexpected ConstArrayAttr elements");
+ }
+
+ return result;
+}
+
+/// ZeroAttr visitor.
+mlir::Value CIRAttrToValue::visitCirAttr(cir::ZeroAttr attr) {
+ auto loc = parentOp->getLoc();
----------------
AmrDeveloper wrote:
Okay, once CI is green I will merge it and create a follow-up fix for this auto
Thanks
https://github.com/llvm/llvm-project/pull/131657
More information about the cfe-commits
mailing list