[MLIR][LLVM] LLVM IR import drops unknown function entry count metadata
Summary
mlir-translate -import-llvm emits an unhandled function metadata warning for valid function-level !prof metadata of the form !{!"unknown", !"pass-name"}. The imported llvm.func has no representation of the attachment. An LLVM IR to LLVM dialect to LLVM IR round trip removes the explicit unknown entry count and its origin pass name.
Version
commit 36c3b79de6442f9b6a9756822d57d0fe7af6f23e
Reproducer
Save the following as input.ll:
define void @unknown_entry_count() !prof !0 {
ret void
}
!0 = !{!"unknown", !"sample-pass"}
Command
llvm-as -disable-output input.ll
mlir-translate -import-llvm input.ll | mlir-translate -mlir-to-llvmir
Actual behavior
llvm-as accepts the input. The round-trip command emits:
warning: unhandled function metadata: !0 = !{!"unknown", !"sample-pass"} on define void @unknown_entry_count() !prof !0
The resulting LLVM IR has no !prof attachment:
define void @unknown_entry_count() {
ret void
}
Expected behavior
The LLVM IR to LLVM dialect to LLVM IR round trip should retain a function-level !prof attachment equivalent to !{!"unknown", !"sample-pass"}.
@llvm/issue-subscribers-mlir-llvm
Author: Akimasa Watanuki (Men-cotton)
mlir-translate -import-llvm emits an unhandled function metadata warning for valid function-level !prof metadata of the form !{!"unknown", !"pass-name"}. The imported llvm.func has no representation of the attachment. An LLVM IR to LLVM dialect to LLVM IR round trip removes the explicit unknown entry count and its origin pass name.
Version
commit 36c3b79de6442f9b6a9756822d57d0fe7af6f23e
Reproducer
Save the following as input.ll:
define void @<!-- -->unknown_entry_count() !prof !0 {
ret void
}
!0 = !{!"unknown", !"sample-pass"}
Command
llvm-as -disable-output input.ll
mlir-translate -import-llvm input.ll | mlir-translate -mlir-to-llvmir
Actual behavior
llvm-as accepts the input. The round-trip command emits:
warning: unhandled function metadata: !0 = !{!"unknown", !"sample-pass"} on define void @<!-- -->unknown_entry_count() !prof !0
The resulting LLVM IR has no !prof attachment:
define void @<!-- -->unknown_entry_count() {
ret void
}
Expected behavior
The LLVM IR to LLVM dialect to LLVM IR round trip should retain a function-level !prof attachment equivalent to !{!"unknown", !"sample-pass"}.
For relevant design context, see this discussion https://github.com/llvm/llvm-project/pull/203018#discussion_r3822359321. It records the rationale for excluding prof from the generic function_metadata carrier and for warning about and dropping unsupported function-level !prof metadata during import. The behavior reported here is the resulting limitation.
Happy to take this one ...
Hi, @hamzaqureshi5!
You’re welcome to work on this, but I expect it to be difficult. The right fix is not obvious and will require some design decisions. If you already have a good approach in mind, please feel free to propose a PR! Otherwise, it may be better to work on another issue.