[Mlir-commits] [mlir] c9e9cc3 - [MLIR] Allow setting "CodeView" flag in LLVMIR translation on MSVC.

Alex Zinenko llvmlistbot at llvm.org
Fri Nov 13 08:31:26 PST 2020


Author: Scott Todd
Date: 2020-11-13T17:31:18+01:00
New Revision: c9e9cc3fe70027ba2472e19d233c6d48ced05fc0

URL: https://github.com/llvm/llvm-project/commit/c9e9cc3fe70027ba2472e19d233c6d48ced05fc0
DIFF: https://github.com/llvm/llvm-project/commit/c9e9cc3fe70027ba2472e19d233c6d48ced05fc0.diff

LOG: [MLIR] Allow setting "CodeView" flag in LLVMIR translation on MSVC.

Reviewed By: ftynse, mehdi_amini

Differential Revision: https://reviews.llvm.org/D91365

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    mlir/lib/Target/LLVMIR/DebugTranslation.cpp
    mlir/test/Target/llvmir.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
index 58dc908183f6..734dd459ca0b 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<void (const Twine &)> 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 a0a19a2c0201..0c745cf976ec 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<StringAttr>().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 89f71477325d..8491e67fdfb5 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 {} {}


        


More information about the Mlir-commits mailing list