[MLIR][LLVM] Preserve pointer-valued metadata operands on LLVM IR import
Summary
mlir-translate -import-llvm cannot represent pointer constants used as LLVM IR metadata operands. If a generic function metadata node contains ptr null or a pointer constant expression, importing it emits an unhandled-metadata warning and drops the entire attachment. An LLVM IR to LLVM dialect to LLVM IR round trip therefore loses valid function metadata.
Version
commit 2eca7a29cf795683ce6aaaf74fa6549273438c57
Reproducer
Save the following as input.ll:
define void @f_null() !associated !0 {
ret void
}
!0 = !{ptr null}
; // -----
@g = addrspace(1) global i32 0
define void @f_cast() !associated !0 {
ret void
}
!0 = !{ptr addrspacecast (ptr addrspace(1) @g to ptr)}
Command
mlir-translate -import-llvm -split-input-file input.ll
Actual behavior
Both inputs are accepted by llvm-as. The import command also succeeds, but it emits warnings for both functions:
warning: unhandled function metadata: !0 = !{ptr null} on define void @f_null() !associated !0
warning: unhandled function metadata: !0 = !{ptr addrspacecast (ptr addrspace(1) @g to ptr)} on define void @f_cast() !associated !0
The relevant excerpts from the two output modules show that neither imported llvm.func operation has a function_metadata attribute:
// First split.
llvm.func @f_null() {
llvm.return
}
// Second split.
llvm.func @f_cast() {
llvm.return
}
Translating the imported modules back to LLVM IR therefore produces functions without !associated.
Expected behavior
The imported MLIR should preserve the pointer-valued metadata operands, including ptr null and the addrspacecast constant expression, so that translating back to LLVM IR can emit equivalent function metadata.
Additional context
This is distinct from #203017, which preserves symbol-backed LLVM global values used as metadata operands. The unsupported operands here are a ConstantPointerNull and a ConstantExpr.
@llvm/issue-subscribers-mlir-llvm
Author: Akimasa Watanuki (Men-cotton)
mlir-translate -import-llvm cannot represent pointer constants used as LLVM IR metadata operands. If a generic function metadata node contains ptr null or a pointer constant expression, importing it emits an unhandled-metadata warning and drops the entire attachment. An LLVM IR to LLVM dialect to LLVM IR round trip therefore loses valid function metadata.
Version
commit 2eca7a29cf795683ce6aaaf74fa6549273438c57
Reproducer
Save the following as input.ll:
define void @<!-- -->f_null() !associated !0 {
ret void
}
!0 = !{ptr null}
; // -----
@<!-- -->g = addrspace(1) global i32 0
define void @<!-- -->f_cast() !associated !0 {
ret void
}
!0 = !{ptr addrspacecast (ptr addrspace(1) @<!-- -->g to ptr)}
Command
mlir-translate -import-llvm -split-input-file input.ll
Actual behavior
Both inputs are accepted by llvm-as. The import command also succeeds, but it emits warnings for both functions:
warning: unhandled function metadata: !0 = !{ptr null} on define void @<!-- -->f_null() !associated !0
warning: unhandled function metadata: !0 = !{ptr addrspacecast (ptr addrspace(1) @<!-- -->g to ptr)} on define void @<!-- -->f_cast() !associated !0
The relevant excerpts from the two output modules show that neither imported llvm.func operation has a function_metadata attribute:
// First split.
llvm.func @<!-- -->f_null() {
llvm.return
}
// Second split.
llvm.func @<!-- -->f_cast() {
llvm.return
}
Translating the imported modules back to LLVM IR therefore produces functions without !associated.
Expected behavior
The imported MLIR should preserve the pointer-valued metadata operands, including ptr null and the addrspacecast constant expression, so that translating back to LLVM IR can emit equivalent function metadata.
Additional context
This is distinct from #203017, which preserves symbol-backed LLVM global values used as metadata operands. The unsupported operands here are a ConstantPointerNull and a ConstantExpr.
@llvm/issue-subscribers-mlir
Author: Akimasa Watanuki (Men-cotton)
mlir-translate -import-llvm cannot represent pointer constants used as LLVM IR metadata operands. If a generic function metadata node contains ptr null or a pointer constant expression, importing it emits an unhandled-metadata warning and drops the entire attachment. An LLVM IR to LLVM dialect to LLVM IR round trip therefore loses valid function metadata.
Version
commit 2eca7a29cf795683ce6aaaf74fa6549273438c57
Reproducer
Save the following as input.ll:
define void @<!-- -->f_null() !associated !0 {
ret void
}
!0 = !{ptr null}
; // -----
@<!-- -->g = addrspace(1) global i32 0
define void @<!-- -->f_cast() !associated !0 {
ret void
}
!0 = !{ptr addrspacecast (ptr addrspace(1) @<!-- -->g to ptr)}
Command
mlir-translate -import-llvm -split-input-file input.ll
Actual behavior
Both inputs are accepted by llvm-as. The import command also succeeds, but it emits warnings for both functions:
warning: unhandled function metadata: !0 = !{ptr null} on define void @<!-- -->f_null() !associated !0
warning: unhandled function metadata: !0 = !{ptr addrspacecast (ptr addrspace(1) @<!-- -->g to ptr)} on define void @<!-- -->f_cast() !associated !0
The relevant excerpts from the two output modules show that neither imported llvm.func operation has a function_metadata attribute:
// First split.
llvm.func @<!-- -->f_null() {
llvm.return
}
// Second split.
llvm.func @<!-- -->f_cast() {
llvm.return
}
Translating the imported modules back to LLVM IR therefore produces functions without !associated.
Expected behavior
The imported MLIR should preserve the pointer-valued metadata operands, including ptr null and the addrspacecast constant expression, so that translating back to LLVM IR can emit equivalent function metadata.
Additional context
This is distinct from #203017, which preserves symbol-backed LLVM global values used as metadata operands. The unsupported operands here are a ConstantPointerNull and a ConstantExpr.