[clang] [CIR] Lowering to LLVM for global pointers (PR #125619)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 4 07:11:03 PST 2025


================
@@ -92,6 +159,16 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
                    mlir::dyn_cast<cir::IntAttr>(init.value())) {
       // Initializer is a constant array: convert it to a compatible llvm init.
       init = rewriter.getIntegerAttr(llvmType, intAttr.getValue());
+    } else if (isa<cir::ConstPtrAttr>(init.value())) {
+      // TODO(cir): once LLVM's dialect has proper equivalent attributes this
+      // should be updated. For now, we use a custom op to initialize globals
+      // to the appropriate value.
+      setupRegionInitializedLLVMGlobalOp();
+      CIRAttrToValue attrVisitor;
+      mlir::Value value = attrVisitor.lowerCirAttrAsValue(
+          op, init.value(), rewriter, typeConverter, dataLayout);
+      rewriter.create<mlir::LLVM::ReturnOp>(loc, value);
+      return mlir::success();
----------------
erichkeane wrote:

Hmm... this already changing to make these not 'equal' in some way is causing me consternation.  I realize this is the reason for an inability to skip the visitor, which I see the reasoning for here, but this function is going to QUICKLY get unreadable without some sort of better organization.

We should noodle on a way to better organize this into something that isn't going to get unwieldy.  And by 'we' I believe that is a group-homework-assignment :) 

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


More information about the cfe-commits mailing list