Skip to content

Commit e82e0fb

Browse files
gysitkcloudy0717
authored andcommitted
[MLIR][LLVM] Fix the import of LLVM IR metadata (llvm#170631)
Change `getSupportedMetadata` to return `SmallVector<unsigned>` instead of `ArrayRef<unsigned>` and make the list non-static. This ensures metadata identifiers are correctly obtained per LLVM context, preventing incorrect import when multiple contexts are used (for metadata like vector hints or work group sizes which have non-static IDs).
1 parent da042e2 commit e82e0fb

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ class LLVMImportDialectInterface
8484

8585
/// Hook for derived dialect interfaces to publish the supported metadata
8686
/// kinds. As every metadata kind has a unique integer identifier, the
87-
/// function returns the list of supported metadata identifiers. `ctx` can be
88-
/// used to obtain IDs of metadata kinds that do not have a fixed static one.
89-
virtual ArrayRef<unsigned>
90-
getSupportedMetadata(llvm::LLVMContext &ctx) const {
87+
/// function returns the list of supported metadata identifiers. The
88+
/// `llvmContext` parameter is used to obtain identifiers for metadata kinds
89+
/// that do not have a fixed static identifier. Since different LLVM contexts
90+
/// can assign different identifiers to these non-static metadata kinds, the
91+
/// function must recompute the list of supported metadata identifiers on each
92+
/// call.
93+
virtual SmallVector<unsigned>
94+
getSupportedMetadata(llvm::LLVMContext &llvmContext) const {
9195
return {};
9296
}
9397
};

mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ static LogicalResult convertIntrinsicImpl(OpBuilder &odsBuilder,
8080

8181
/// Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM
8282
/// dialect attributes.
83-
static ArrayRef<unsigned> getSupportedMetadataImpl(llvm::LLVMContext &context) {
84-
static const SmallVector<unsigned> convertibleMetadata = {
83+
static SmallVector<unsigned>
84+
getSupportedMetadataImpl(llvm::LLVMContext &llvmContext) {
85+
SmallVector<unsigned> convertibleMetadata = {
8586
llvm::LLVMContext::MD_prof,
8687
llvm::LLVMContext::MD_tbaa,
8788
llvm::LLVMContext::MD_access_group,
@@ -91,10 +92,10 @@ static ArrayRef<unsigned> getSupportedMetadataImpl(llvm::LLVMContext &context) {
9192
llvm::LLVMContext::MD_dereferenceable,
9293
llvm::LLVMContext::MD_dereferenceable_or_null,
9394
llvm::LLVMContext::MD_mmra,
94-
context.getMDKindID(vecTypeHintMDName),
95-
context.getMDKindID(workGroupSizeHintMDName),
96-
context.getMDKindID(reqdWorkGroupSizeMDName),
97-
context.getMDKindID(intelReqdSubGroupSizeMDName)};
95+
llvmContext.getMDKindID(vecTypeHintMDName),
96+
llvmContext.getMDKindID(workGroupSizeHintMDName),
97+
llvmContext.getMDKindID(reqdWorkGroupSizeMDName),
98+
llvmContext.getMDKindID(intelReqdSubGroupSizeMDName)};
9899
return convertibleMetadata;
99100
}
100101

@@ -505,9 +506,9 @@ class LLVMDialectLLVMIRImportInterface : public LLVMImportDialectInterface {
505506

506507
/// Returns the list of LLVM IR metadata kinds that are convertible to MLIR
507508
/// LLVM dialect attributes.
508-
ArrayRef<unsigned>
509-
getSupportedMetadata(llvm::LLVMContext &context) const final {
510-
return getSupportedMetadataImpl(context);
509+
SmallVector<unsigned>
510+
getSupportedMetadata(llvm::LLVMContext &llvmContext) const final {
511+
return getSupportedMetadataImpl(llvmContext);
511512
}
512513
};
513514
} // namespace

0 commit comments

Comments
 (0)