From c9e9cc3fe70027ba2472e19d233c6d48ced05fc0 Mon Sep 17 00:00:00 2001 From: Scott Todd Date: Fri, 13 Nov 2020 17:30:36 +0100 Subject: [PATCH] [MLIR] Allow setting "CodeView" flag in LLVMIR translation on MSVC. Reviewed By: ftynse, mehdi_amini Differential Revision: https://reviews.llvm.org/D91365 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td | 3 +++ mlir/lib/Target/LLVMIR/DebugTranslation.cpp | 11 +++++++++++ mlir/test/Target/llvmir.mlir | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td index 58dc908..734dd45 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -37,6 +37,9 @@ def LLVM_Dialect : Dialect { /// 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 index a0a19a2..0c745cf 100644 --- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp @@ -48,6 +48,17 @@ DebugTranslation::DebugTranslation(Operation *module, llvm::Module &llvmModule) 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. diff --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir index 89f7147..8491e67 100644 --- a/mlir/test/Target/llvmir.mlir +++ b/mlir/test/Target/llvmir.mlir @@ -1311,3 +1311,17 @@ module attributes {llvm.data_layout = "E"} { llvm.func @module_big_endian() } +// ----- + +// CHECK: "CodeView", i32 1 +module attributes {llvm.target_triple = "x86_64-pc-windows-msvc"} {} + +// ----- + +// CHECK-NOT: "CodeView", i32 1 +module attributes {llvm.target_triple = "aarch64-linux-android"} {} + +// ----- + +// CHECK-NOT: "CodeView", i32 1 +module attributes {} {} -- 2.7.4