[clang] [CIR][NFC] Add amendOperation to CIRDialectLLVMIRTranslationInterface (PR #186073)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 03:48:30 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir
@llvm/pr-subscribers-clang
Author: Chaitanya (skc7)
<details>
<summary>Changes</summary>
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
These changes are pre-requisite for https://github.com/llvm/llvm-project/pull/186081
---
Full diff: https://github.com/llvm/llvm-project/pull/186073.diff
1 Files Affected:
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp (+29)
``````````diff
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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/186073
More information about the cfe-commits
mailing list