[Mlir-commits] [mlir] [mlir][LLVM] Add the `ConvertToLLVMAttrInterface` and `ConvertToLLVMOpInterface` interfaces (PR #99566)
Fabian Mora
llvmlistbot at llvm.org
Sat Jul 27 05:44:54 PDT 2024
================
@@ -30,3 +30,20 @@ void mlir::populateConversionTargetFromOperation(
patterns);
});
}
+
+void mlir::populateOpConvertToLLVMConversionPatterns(
+ Operation *op, ConversionTarget &target, LLVMTypeConverter &typeConverter,
+ RewritePatternSet &patterns) {
+ auto iface = dyn_cast<ConvertToLLVMOpInterface>(op);
+ if (!iface)
+ return;
+ SmallVector<ConvertToLLVMAttrInterface, 12> attrs;
+ iface.getConvertToLLVMConversionAttrs(attrs);
+ for (ConvertToLLVMAttrInterface attr : attrs)
+ attr.populateConvertToLLVMConversionPatterns(target, typeConverter,
+ patterns);
+}
----------------
fabianmcg wrote:
How about if the anchor interface is changed to:
```c++
ConvertToLLVMOpInterface getConvertToLLVMOpInterface(Operation* op) {
if (auto iface = dyn_cast<ConvertToLLVMOpInterface>(op))
return iface;
return op->getParentOfType<ConvertToLLVMOpInterface>();
}
// ... ConvertToLLVMPass::runOnOperation()
ConvertToLLVMOpInterface iface = getConvertToLLVMOpInterface(getOperation());
...
```
In that case, anything inside of a `ConvertToLLVMOpInterface` would get converted according to a target.
https://github.com/llvm/llvm-project/pull/99566
More information about the Mlir-commits
mailing list