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

2025-02-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/125619 >From dc7f71d511d2e13e527e0c8cd242a3ece82bcdfd Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 3 Feb 2025 13:20:51 -0800 Subject: [PATCH 1/4] [CIR] Lowering to LLVM for global pointers Add support for

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

2025-02-05 Thread Bruno Cardoso Lopes via cfe-commits
@@ -0,0 +1,52 @@ +//===- TypeConverter.h - Convert builtin to LLVM dialect types --*- C++ -*-===// bcardosolopes wrote: TypeConverter.h -> CIRAttrVisitor.h https://github.com/llvm/llvm-project/pull/125619 ___ cfe-comm

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

2025-02-05 Thread Bruno Cardoso Lopes via cfe-commits
bcardosolopes wrote: > @lanza @bcardosolopes Do you want to look this over before I commit it? This > change introduces some restructuring that I'll want to incorporate in the > incubator, where it will have a somewhat bigger impact, so I'd like to get > your buy-in or objections now before I

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

2025-02-05 Thread Andy Kaylor via cfe-commits
andykaylor wrote: @lanza @bcardosolopes Do you want to look this over before I commit it? This change introduces some restructuring that I'll want to incorporate in the incubator, where it will have a somewhat bigger impact, so I'd like to get your buy-in or objections now before I start worki

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

2025-02-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/125619 >From dc7f71d511d2e13e527e0c8cd242a3ece82bcdfd Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 3 Feb 2025 13:20:51 -0800 Subject: [PATCH 1/3] [CIR] Lowering to LLVM for global pointers Add support for

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

2025-02-04 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/125619 >From dc7f71d511d2e13e527e0c8cd242a3ece82bcdfd Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 3 Feb 2025 13:20:51 -0800 Subject: [PATCH 1/2] [CIR] Lowering to LLVM for global pointers Add support for

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -84,6 +138,19 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( SmallVector attributes; if (init.has_value()) { +auto setupRegionInitializedLLVMGlobalOp = [&]() { erichkeane wrote: Ah, hrmph. That is unfortunately a much nicer ve

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

2025-02-04 Thread Andy Kaylor via cfe-commits
@@ -84,6 +138,19 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( SmallVector attributes; if (init.has_value()) { +auto setupRegionInitializedLLVMGlobalOp = [&]() { andykaylor wrote: It's not quite as bad there because everything is

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

2025-02-04 Thread Andy Kaylor via cfe-commits
@@ -84,6 +138,19 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( SmallVector attributes; if (init.has_value()) { +auto setupRegionInitializedLLVMGlobalOp = [&]() { andykaylor wrote: https://github.com/llvm/clangir/blob/f8821e852168

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -92,6 +159,16 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( mlir::dyn_cast(init.value())) { // Initializer is a constant array: convert it to a compatible llvm init. init = rewriter.getIntegerAttr(llvmType, intAttr.getValu

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -0,0 +1,51 @@ +#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H +#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H + +#include "clang/CIR/Dialect/IR/CIRAttrs.h" + +namespace cir { + +template class CirAttrVisitor { +public: + // FIXME: Create a TableGen list to automatical

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -55,14 +104,19 @@ struct ConvertCIRToLLVMPass StringRef getArgument() const override { return "cir-flat-to-llvm"; } }; +/// Replace CIR global with a region initialized LLVM global and update +/// insertion point to the end of the initializer block. + mlir::LogicalResult

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -0,0 +1,51 @@ +#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H +#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H + +#include "clang/CIR/Dialect/IR/CIRAttrs.h" + +namespace cir { + +template class CirAttrVisitor { +public: + // FIXME: Create a TableGen list to automatical

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -35,6 +36,54 @@ using namespace llvm; namespace cir { namespace direct { +class CIRAttrToValue : public CirAttrVisitor { +public: + mlir::Value lowerCirAttrAsValue(mlir::Operation *parentOp, + mlir::Attribute attr, +

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -0,0 +1,51 @@ +#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H +#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H + +#include "clang/CIR/Dialect/IR/CIRAttrs.h" + +namespace cir { + +template class CirAttrVisitor { +public: + // FIXME: Create a TableGen list to automatical

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -35,6 +36,54 @@ using namespace llvm; namespace cir { namespace direct { +class CIRAttrToValue : public CirAttrVisitor { +public: + mlir::Value lowerCirAttrAsValue(mlir::Operation *parentOp, + mlir::Attribute attr, +

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

2025-02-04 Thread Erich Keane via cfe-commits
@@ -84,6 +138,19 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( SmallVector attributes; if (init.has_value()) { +auto setupRegionInitializedLLVMGlobalOp = [&]() { erichkeane wrote: I think I'd prefer this get extracted to a functi

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

2025-02-03 Thread Andy Kaylor via cfe-commits
andykaylor wrote: This patch includes an experimental attempt at a CIR attribute visitor along the lines that @erichkeane suggested in a previous PR review. Unfortunately, I wasn't able to use the new visitor in the place that he suggested it without an ugly shoehorn because different handlers

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

2025-02-03 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Andy Kaylor (andykaylor) Changes Add support for lowering global variables of any pointer type to LLVM IR. --- Full diff: https://github.com/llvm/llvm-project/pull/125619.diff 4 Files Affected: - (added) clang/include/clang/CIR/Dialect/

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

2025-02-03 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/125619 Add support for lowering global variables of any pointer type to LLVM IR. >From dc7f71d511d2e13e527e0c8cd242a3ece82bcdfd Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 3 Feb 2025 13:20:51 -0800 Subjec