diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2025-03-14 18:03:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-14 18:03:36 -0700 |
commit | 29a000023caf5b0b02a5d8b517d03f9538e2885e (patch) | |
tree | 79ddf40361a5bddb6f1df1ccd98ff13f86d8140e /mlir/lib/Target/LLVMIR/ModuleImport.cpp | |
parent | b7852939b59231181f98d60d3bbb9b5273019f66 (diff) | |
download | llvm-29a000023caf5b0b02a5d8b517d03f9538e2885e.zip llvm-29a000023caf5b0b02a5d8b517d03f9538e2885e.tar.gz llvm-29a000023caf5b0b02a5d8b517d03f9538e2885e.tar.bz2 |
[MLIR][LLVMIR] Add module flags support (#130679)
Import and translation support.
Note that existing support (prior to this PR) already covers enough in
translation specifically to emit "Debug Info Version". Also, the debug
info version metadata is being emitted even though the imported IR has
no information and is showing up in some tests (will fix that in another
PR).
---------
Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
Diffstat (limited to 'mlir/lib/Target/LLVMIR/ModuleImport.cpp')
-rw-r--r-- | mlir/lib/Target/LLVMIR/ModuleImport.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index ab187cd..663cad7 100644 --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -517,6 +517,33 @@ void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) { debugIntrinsics.insert(intrinsic); } +LogicalResult ModuleImport::convertModuleFlagsMetadata() { + SmallVector<llvm::Module::ModuleFlagEntry> llvmModuleFlags; + llvmModule->getModuleFlagsMetadata(llvmModuleFlags); + + SmallVector<Attribute> moduleFlags; + for (const auto [behavior, key, val] : llvmModuleFlags) { + // Currently only supports most common: int constant values. + auto *constInt = llvm::mdconst::dyn_extract<llvm::ConstantInt>(val); + if (!constInt) { + emitWarning(mlirModule.getLoc()) + << "unsupported module flag value: " << diagMD(val, llvmModule.get()) + << ", only constant integer currently supported"; + continue; + } + + moduleFlags.push_back(builder.getAttr<ModuleFlagAttr>( + convertModFlagBehaviorFromLLVM(behavior), + builder.getStringAttr(key->getString()), constInt->getZExtValue())); + } + + if (!moduleFlags.empty()) + builder.create<LLVM::ModuleFlagsOp>(mlirModule.getLoc(), + builder.getArrayAttr(moduleFlags)); + + return success(); +} + LogicalResult ModuleImport::convertLinkerOptionsMetadata() { for (const llvm::NamedMDNode &named : llvmModule->named_metadata()) { if (named.getName() != "llvm.linker.options") @@ -596,6 +623,8 @@ LogicalResult ModuleImport::convertMetadata() { } if (failed(convertLinkerOptionsMetadata())) return failure(); + if (failed(convertModuleFlagsMetadata())) + return failure(); if (failed(convertIdentMetadata())) return failure(); if (failed(convertCommandlineMetadata())) |