@@ -344,6 +344,15 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
344344 IRGenDebugInfoFormat getDebugInfoFormat () { return Opts.DebugInfoFormat ; }
345345
346346private:
347+ // / Convert a SILLocation into the corresponding LLVM Loc.
348+ FileAndLocation computeLLVMLoc (const SILDebugScope *DS, SILLocation Loc);
349+
350+ // / Compute the LLVM DebugLoc when targeting CodeView. In CodeView, zero is
351+ // / not an artificial line location; attempt to avoid those line locations near
352+ // / user code to reduce the number of breaks in the linetables.
353+ FileAndLocation computeLLVMLocCodeView (const SILDebugScope *DS,
354+ SILLocation Loc);
355+
347356 static StringRef getFilenameFromDC (const DeclContext *DC) {
348357 if (auto *LF = dyn_cast<LoadedFile>(DC))
349358 return LF->getFilename ();
@@ -2614,6 +2623,40 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL,
26142623}
26152624#endif
26162625
2626+ IRGenDebugInfoImpl::FileAndLocation
2627+ IRGenDebugInfoImpl::computeLLVMLocCodeView (const SILDebugScope *DS,
2628+ SILLocation Loc) {
2629+ // If the scope has not changed and the line number is either zero or
2630+ // artificial, we want to keep the most recent debug location.
2631+ if (DS == LastScope && (Loc.is <ArtificialUnreachableLocation>() ||
2632+ Loc.isLineZero (SM) || Loc.isHiddenFromDebugInfo ()))
2633+ return LastFileAndLocation;
2634+
2635+ // Decode the location.
2636+ return decodeFileAndLocation (Loc);
2637+ }
2638+
2639+ IRGenDebugInfoImpl::FileAndLocation
2640+ IRGenDebugInfoImpl::computeLLVMLoc (const SILDebugScope *DS, SILLocation Loc) {
2641+ SILFunction *Fn = DS->getInlinedFunction ();
2642+ if (Fn && (Fn->isThunk () || Fn->isTransparent ()))
2643+ return {0 , 0 , CompilerGeneratedFile};
2644+
2645+ if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2646+ return computeLLVMLocCodeView (DS, Loc);
2647+
2648+ FileAndLocation L =
2649+ Loc.isInPrologue () ? FileAndLocation () : decodeFileAndLocation (Loc);
2650+
2651+ // Otherwise use a line 0 artificial location, but the file from the location.
2652+ if (Loc.isHiddenFromDebugInfo ()) {
2653+ L.Line = 0 ;
2654+ L.Column = 0 ;
2655+ }
2656+
2657+ return L;
2658+ }
2659+
26172660void IRGenDebugInfoImpl::setCurrentLoc (IRBuilder &Builder,
26182661 const SILDebugScope *DS,
26192662 SILLocation Loc) {
@@ -2622,38 +2665,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
26222665 if (!Scope)
26232666 return ;
26242667
2625- // NOTE: In CodeView, zero is not an artificial line location. We try to
2626- // avoid those line locations near user code to reduce the number
2627- // of breaks in the linetables.
2628- FileAndLocation L;
2629- SILFunction *Fn = DS->getInlinedFunction ();
2630- if (Fn && (Fn->isThunk () || Fn->isTransparent ())) {
2631- L = {0 , 0 , CompilerGeneratedFile};
2632- } else if (DS == LastScope && Loc.isHiddenFromDebugInfo ()) {
2633- // Reuse the last source location if we are still in the same
2634- // scope to get a more contiguous line table.
2635- L = LastFileAndLocation;
2636- } else if (DS == LastScope &&
2637- (Loc.is <ArtificialUnreachableLocation>() || Loc.isLineZero (SM)) &&
2638- Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView) {
2639- // If the scope has not changed and the line number is either zero or
2640- // artificial, we want to keep the most recent debug location.
2641- L = LastFileAndLocation;
2642- } else {
2643- // Decode the location.
2644- if (!Loc.isInPrologue () ||
2645- Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2646- L = decodeFileAndLocation (Loc);
2647-
2648- // Otherwise use a line 0 artificial location, but the file from the
2649- // location. If we are emitting CodeView, we do not want to use line zero
2650- // since it does not represent an artificial line location.
2651- if (Loc.isHiddenFromDebugInfo () &&
2652- Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView) {
2653- L.Line = 0 ;
2654- L.Column = 0 ;
2655- }
2656- }
2668+ FileAndLocation L = computeLLVMLoc (DS, Loc);
26572669
26582670 if (L.getFilename () != Scope->getFilename ()) {
26592671 // We changed files in the middle of a scope. This happens, for
0 commit comments