[Mlir-commits] [mlir] [MLIR][LLVMIR] Add support for intrinsics with metadata arguments (PR #200308)
Andy Kaylor
llvmlistbot at llvm.org
Wed Jun 3 11:53:02 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)
----------------
andykaylor wrote:
I don't think `mdAsValue` can have a location. `llvm::MetadataAsValue` derives from `llvm::Value` but not from `llvm::Instruction` which is where debug locations are attached.
I'll add the value mapping.
https://github.com/llvm/llvm-project/pull/200308
More information about the Mlir-commits
mailing list