[Mlir-commits] [mlir] [mlir] Add `convertInstruction` and `getSupportedInstructions` to `LLVMImportInterface` (PR #86799)

Fabian Mora llvmlistbot at llvm.org
Wed Mar 27 14:15:30 PDT 2024


================
@@ -66,6 +75,11 @@ class LLVMImportDialectInterface
   /// returns the list of supported intrinsic identifiers.
   virtual ArrayRef<unsigned> getSupportedIntrinsics() const { return {}; }
 
+  /// Hook for derived dialect interfaces to publish the supported instructions.
+  /// As every LLVM IR instructions has a unique integer identifier, the
+  /// function returns the list of supported instructions identifiers.
+  virtual ArrayRef<unsigned> getSupportedInstructions() const { return {}; }
----------------
fabianmcg wrote:

If multiple dialects try to register the same instruction the interface emits an error and aborts the entire translation, see the `initializeImport` method.
Small caveat: this mechanism doesn't check if it's colliding with LLVM tablegen conversions, only with respect to other interfaces -which I'd argue is okay, bc allows overriding LLVM behavior.

With respect to how should be used, I added a test where:
```llvm
%1 = load double, ptr %ptr 
```
gets imported as:
```mlir
 %1  = llvm.load %pt : !llvm.ptr -> f64
 %2 = "test.same_operand_element_type"(%1, %1) : 
```
I'll add to the docs that this allows overriding LLVM behavior.

https://github.com/llvm/llvm-project/pull/86799


More information about the Mlir-commits mailing list