diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -35,6 +35,9 @@ /// Uses `reportError` to report errors. static LogicalResult verifyDataLayoutString( StringRef descr, llvm::function_ref reportError); + + /// Name of the target triple attribute. + static StringRef getTargetTripleAttrName() { return "llvm.target_triple"; } }]; } diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -48,6 +48,17 @@ if (!llvmModule.getModuleFlag(debugVersionKey)) llvmModule.addModuleFlag(llvm::Module::Warning, debugVersionKey, llvm::DEBUG_METADATA_VERSION); + + if (auto targetTripleAttr = + module->getAttr(LLVM::LLVMDialect::getTargetTripleAttrName())) { + auto targetTriple = + llvm::Triple(targetTripleAttr.cast().getValue()); + if (targetTriple.isKnownWindowsMSVCEnvironment()) { + // Dwarf debugging files will be generated by default, unless "CodeView" + // is set explicitly. Windows/MSVC should use CodeView instead. + llvmModule.addModuleFlag(llvm::Module::Warning, "CodeView", 1); + } + } } /// Finalize the translation of debug information.