[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 31 11:08:48 PST 2025
================
@@ -22,13 +34,127 @@ using namespace llvm;
namespace cir {
namespace direct {
+struct ConvertCIRToLLVMPass
+ : public mlir::PassWrapper<ConvertCIRToLLVMPass,
+ mlir::OperationPass<mlir::ModuleOp>> {
+ void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+ registry.insert<mlir::BuiltinDialect, mlir::DLTIDialect,
+ mlir::LLVM::LLVMDialect, mlir::func::FuncDialect>();
+ }
+ void runOnOperation() final;
+
+ StringRef getDescription() const override {
+ return "Convert the prepared CIR dialect module to LLVM dialect";
+ }
+
+ StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+ cir::GlobalOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+
+ // Fetch required values to create LLVM op.
+ const mlir::Type cirSymType = op.getSymType();
+
+ // This is the LLVM dialect type
+ const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+ // These defaults are just here until the equivalent attributes are
+ // available on cir.global ops.
+ const bool isConst = false;
+ const bool isDsoLocal = true;
----------------
andykaylor wrote:
That sounds reasonable. I haven't dug into all the cases that will be handled here, so there might be some cases where that doesn't work, but I can at least put placeholders here for now.
https://github.com/llvm/llvm-project/pull/125260
More information about the cfe-commits
mailing list