diff --git a/mlir/include/mlir/Target/LLVMIR.h b/mlir/include/mlir/Target/LLVMIR.h --- a/mlir/include/mlir/Target/LLVMIR.h +++ b/mlir/include/mlir/Target/LLVMIR.h @@ -15,6 +15,7 @@ #include "mlir/Support/LLVM.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" #include // Forward-declare LLVM classes. @@ -35,7 +36,8 @@ /// the MLIR module), and return `nullptr`. std::unique_ptr translateModuleToLLVMIR(ModuleOp m, llvm::LLVMContext &llvmContext, - StringRef name = "LLVMDialectModule"); + StringRef name = "LLVMDialectModule", + llvm::Triple configTriple = llvm::Triple()); /// Convert the given LLVM module into MLIR's LLVM dialect. The LLVM context is /// extracted from the registered LLVM IR dialect. In case of error, report it diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h --- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h +++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h @@ -21,6 +21,7 @@ #include "mlir/IR/Value.h" #include "mlir/Target/LLVMIR/TypeTranslation.h" +#include "llvm/ADT/Triple.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" @@ -52,13 +53,14 @@ template static std::unique_ptr translateModule(Operation *m, llvm::LLVMContext &llvmContext, - StringRef name = "LLVMDialectModule") { + StringRef name = "LLVMDialectModule", + llvm::Triple configTriple = llvm::Triple()) { if (!satisfiesLLVMModule(m)) return nullptr; if (failed(checkSupportedModuleOps(m))) return nullptr; std::unique_ptr llvmModule = - prepareLLVMModule(m, llvmContext, name); + prepareLLVMModule(m, llvmContext, name, configTriple); LLVM::ensureDistinctSuccessors(m); @@ -97,7 +99,7 @@ static std::unique_ptr prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext, - StringRef name); + StringRef name, llvm::Triple configTriple); /// A helper to look up remapped operands in the value remapping table. SmallVector lookupValues(ValueRange values); diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -17,6 +17,7 @@ #include "mlir/Translation.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/ToolOutputFile.h" @@ -25,7 +26,7 @@ std::unique_ptr mlir::translateModuleToLLVMIR(ModuleOp m, llvm::LLVMContext &llvmContext, - StringRef name) { + StringRef name, llvm::Triple triple) { auto llvmModule = LLVM::ModuleTranslation::translateModule<>(m, llvmContext, name); if (!llvmModule) diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -938,7 +938,8 @@ } std::unique_ptr ModuleTranslation::prepareLLVMModule( - Operation *m, llvm::LLVMContext &llvmContext, StringRef name) { + Operation *m, llvm::LLVMContext &llvmContext, StringRef name, + llvm::Triple configTriple) { m->getContext()->getOrLoadDialect(); auto llvmModule = std::make_unique(name, llvmContext); if (auto dataLayoutAttr = @@ -953,5 +954,11 @@ llvmModule->getOrInsertFunction("free", builder.getVoidTy(), builder.getInt8PtrTy()); + if (configTriple.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); + } + return llvmModule; }