Skip to content

Commit c9e9cc3

Browse files
ScottToddftynse
authored andcommitted
[MLIR] Allow setting "CodeView" flag in LLVMIR translation on MSVC.
Reviewed By: ftynse, mehdi_amini Differential Revision: https://reviews.llvm.org/D91365
1 parent e7eb2ac commit c9e9cc3

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def LLVM_Dialect : Dialect {
3737
/// Uses `reportError` to report errors.
3838
static LogicalResult verifyDataLayoutString(
3939
StringRef descr, llvm::function_ref<void (const Twine &)> reportError);
40+
41+
/// Name of the target triple attribute.
42+
static StringRef getTargetTripleAttrName() { return "llvm.target_triple"; }
4043
}];
4144
}
4245

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ DebugTranslation::DebugTranslation(Operation *module, llvm::Module &llvmModule)
4848
if (!llvmModule.getModuleFlag(debugVersionKey))
4949
llvmModule.addModuleFlag(llvm::Module::Warning, debugVersionKey,
5050
llvm::DEBUG_METADATA_VERSION);
51+
52+
if (auto targetTripleAttr =
53+
module->getAttr(LLVM::LLVMDialect::getTargetTripleAttrName())) {
54+
auto targetTriple =
55+
llvm::Triple(targetTripleAttr.cast<StringAttr>().getValue());
56+
if (targetTriple.isKnownWindowsMSVCEnvironment()) {
57+
// Dwarf debugging files will be generated by default, unless "CodeView"
58+
// is set explicitly. Windows/MSVC should use CodeView instead.
59+
llvmModule.addModuleFlag(llvm::Module::Warning, "CodeView", 1);
60+
}
61+
}
5162
}
5263

5364
/// Finalize the translation of debug information.

mlir/test/Target/llvmir.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,3 +1311,17 @@ module attributes {llvm.data_layout = "E"} {
13111311
llvm.func @module_big_endian()
13121312
}
13131313

1314+
// -----
1315+
1316+
// CHECK: "CodeView", i32 1
1317+
module attributes {llvm.target_triple = "x86_64-pc-windows-msvc"} {}
1318+
1319+
// -----
1320+
1321+
// CHECK-NOT: "CodeView", i32 1
1322+
module attributes {llvm.target_triple = "aarch64-linux-android"} {}
1323+
1324+
// -----
1325+
1326+
// CHECK-NOT: "CodeView", i32 1
1327+
module attributes {} {}

0 commit comments

Comments
 (0)