@@ -32,31 +32,29 @@ DebugTranslation::DebugTranslation(Operation *module, llvm::Module &llvmModule)
3232 if (!module ->walk (interruptIfValidLocation).wasInterrupted ())
3333 return ;
3434 debugEmissionIsEnabled = true ;
35+ }
36+
37+ static constexpr StringRef kDebugVersionKey = " Debug Info Version" ;
38+ static constexpr StringRef kCodeViewKey = " CodeView" ;
3539
40+ void DebugTranslation::addModuleFlagsIfNotPresent () {
3641 // TODO: The version information should be encoded on the LLVM module itself,
3742 // not implicitly set here.
3843
3944 // Mark this module as having debug information.
40- StringRef debugVersionKey = " Debug Info Version" ;
41- if (!llvmModule.getModuleFlag (debugVersionKey))
42- llvmModule.addModuleFlag (llvm::Module::Warning, debugVersionKey,
45+ if (!llvmModule.getModuleFlag (kDebugVersionKey ))
46+ llvmModule.addModuleFlag (llvm::Module::Warning, kDebugVersionKey ,
4347 llvm::DEBUG_METADATA_VERSION);
4448
45- if (auto targetTripleAttr = module ->getDiscardableAttr (
46- LLVM::LLVMDialect::getTargetTripleAttrName ())) {
47- auto targetTriple =
48- llvm::Triple (cast<StringAttr>(targetTripleAttr).getValue ());
49- if (targetTriple.isKnownWindowsMSVCEnvironment ()) {
50- // Dwarf debugging files will be generated by default, unless "CodeView"
51- // is set explicitly. Windows/MSVC should use CodeView instead.
52- llvmModule.addModuleFlag (llvm::Module::Warning, " CodeView" , 1 );
53- }
49+ const llvm::Triple &targetTriple = llvmModule.getTargetTriple ();
50+ if (targetTriple.isKnownWindowsMSVCEnvironment ()) {
51+ // Dwarf debugging files will be generated by default, unless "CodeView"
52+ // is set explicitly. Windows/MSVC should use CodeView instead.
53+ if (!llvmModule.getModuleFlag (kCodeViewKey ))
54+ llvmModule.addModuleFlag (llvm::Module::Warning, kCodeViewKey , 1 );
5455 }
5556}
5657
57- // / Finalize the translation of debug information.
58- void DebugTranslation::finalize () {}
59-
6058// / Translate the debug information for the given function.
6159void DebugTranslation::translate (LLVMFuncOp func, llvm::Function &llvmFunc) {
6260 if (!debugEmissionIsEnabled)
0 commit comments