Commit c9e9cc3f authored by Scott Todd's avatar Scott Todd Committed by Alex Zinenko
Browse files

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

Reviewed By: ftynse, mehdi_amini

Differential Revision: https://reviews.llvm.org/D91365
parent e7eb2ac5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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"; }
  }];
}

+11 −0
Original line number Diff line number Diff line
@@ -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.
+14 −0
Original line number Diff line number Diff line
@@ -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 {} {}