[Mlir-commits] [mlir] [MLIR][LLVMIR] Add support for intrinsics with metadata arguments (PR #200308)

Tobias Gysi llvmlistbot at llvm.org
Wed Jun 3 07:23:10 PDT 2026


================
@@ -1904,8 +1971,20 @@ FailureOr<Value> ModuleImport::convertConstantExpr(llvm::Constant *constant) {
 }
 
 FailureOr<Value> ModuleImport::convertValue(llvm::Value *value) {
-  assert(!isa<llvm::MetadataAsValue>(value) &&
-         "expected value to not be metadata");
+  // `llvm::MetadataAsValue` operands (e.g. the rounding-mode / FP-exception
+  // MDString arguments used by the constrained floating-point intrinsics, or
+  // the named-register MDNode used by `llvm.read_register`) are lifted into a
+  // `llvm.mlir.metadata_as_value` SSA op carrying the corresponding metadata
+  // attribute.
+  if (auto *mdAsVal = dyn_cast<llvm::MetadataAsValue>(value)) {
+    llvm::Metadata *md = mdAsVal->getMetadata();
+    Attribute mdAttr = convertMetadataToAttr(context, md);
+    if (!mdAttr)
+      return emitError(mlirModule.getLoc())
+             << "unsupported metadata: " << diagMD(md, llvmModule.get());
+    return MetadataAsValueOp::create(builder, UnknownLoc::get(context), mdAttr)
----------------
gysit wrote:

Does the `mdsAsVal` have a location? Then we could use translateLoc.

We may also add a mapping between the LLVM and MLIR value in valueMapping and move the code below at the beginning of the function. Then repeated uses of the same MetadataAsValue values are only translated once.

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


More information about the Mlir-commits mailing list