https://github.com/skc7 created https://github.com/llvm/llvm-project/pull/186073
Add the amendOperation override to handle CIR dialect attributes during MLIR-to-LLVM IR translation. This dispatches to amendFunction for LLVMFuncOp and amendModule for ModuleOp, enabling future translation of CIR-specific attributes to LLVM function attributes and module metadata. Upstreaming basic changes from clangIR PRs: https://github.com/llvm/clangir/commit/61e9ebd9f80393a0d6d792142642e8edddbe1adc https://github.com/llvm/clangir/pull/768 https://github.com/llvm/clangir/pull/773 >From ef38d27602a43ffe9ef38065c9815eb8d6d70998 Mon Sep 17 00:00:00 2001 From: skc7 <[email protected]> Date: Thu, 12 Mar 2026 15:28:39 +0530 Subject: [PATCH] [CIR][NFC] Add amendOperation to CIRDialectLLVMIRTranslationInterface --- .../Lowering/DirectToLLVM/LowerToLLVMIR.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp index 30b9eaaca2d37..8de63bfb169a6 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp @@ -47,6 +47,35 @@ class CIRDialectLLVMIRTranslationInterface return mlir::success(); } + + /// Any named attribute in the CIR dialect, i.e, with name started with + /// "cir.", will be handled here. + virtual mlir::LogicalResult amendOperation( + mlir::Operation *op, llvm::ArrayRef<llvm::Instruction *> instructions, + mlir::NamedAttribute attribute, + mlir::LLVM::ModuleTranslation &moduleTranslation) const override { + if (auto func = dyn_cast<mlir::LLVM::LLVMFuncOp>(op)) { + amendFunction(func, instructions, attribute, moduleTranslation); + } else if (auto mod = dyn_cast<mlir::ModuleOp>(op)) { + amendModule(mod, attribute, moduleTranslation); + } + return mlir::success(); + } + +private: + // Translate CIR's extra function attributes to LLVM's function attributes. + void amendFunction(mlir::LLVM::LLVMFuncOp func, + llvm::ArrayRef<llvm::Instruction *> instructions, + mlir::NamedAttribute attribute, + mlir::LLVM::ModuleTranslation &moduleTranslation) const { + // TODO(cir): Implement this + } + + // Translate CIR's module attributes to LLVM's module metadata + void amendModule(mlir::ModuleOp mod, mlir::NamedAttribute attribute, + mlir::LLVM::ModuleTranslation &moduleTranslation) const { + // TODO(cir): Implement this + } }; void registerCIRDialectTranslation(mlir::DialectRegistry ®istry) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
