Commit Graph

141 Commits

Author SHA1 Message Date
eeckstein
af3765e95b Revert "Reduce breaks in Codeview linetables" 2018-07-31 22:28:43 -07:00
Ellis Hoag
0c2ca3d6a0 Reduce breaks in Codeview linetables
Summary:
CodeView does not recognize zero as an artificial line location
and so a line location of zero causes unexpected behavior when
stepping through user code. If we find a line location of zero
and our scope has not changed, we use the most recent debug
location. That is expected to be the user code that most likely
relates to the current instruction and is similar to the behavior
in LLDB.

Test Plan:
test/DebugInfo/linetable-codeview.swift
2018-07-27 15:52:15 -07:00
Davide Italiano
dc85c0a469 Merge pull request #17426 from sparkasaurusRex/codeview-linetables
[IRGen] Fix debug locations to work well with CodeView
2018-07-20 09:54:31 -07:00
Ellis Hoag
8200916129 Fix debug locations to work well with CodeView
Summary:
There are a few problems with how Swift currently emits location
information for CodeView.

1. WinDbg does not work well with column information so all column
locations must be set to zero.

2. Some instructions, e.g., ``a + b``,  will emit ``@llvm.trap()``
and ``unreachable``. Those instructions should have artificial
locations, i.e., they should have a line location of zero.

3. Some instructions, e.g., ``a / b``, will emit ``unreachable``
sandwiched between other code for that instruction. This makes
WinDbg confused and it cannot decide which set of instructions
to break on. Those instructions should have the same line location
as the others.

4. There are several prologue instructions with artificial line
locations that create breaks in the linetables. Those instructions
should have valid line locations, usually at the start of the
function.

5. Case bodies have cleanup instructions with artificial line
locations unless it has a ``do`` block. Those locations should
be the last line in the case block.

Test Plan:
test/DebugInfo/basic.swift
test/DebugInfo/columns.swift
test/DebugInfo/linetable-codeview.swift
test/DebugInfo/line-directive-codeview.swift
2018-07-18 09:54:19 -07:00
Adrian Prantl
60c71c9b33 Point the SILLocations of function-level SILDebugScopes to the beginning of the scope.
This mostly makes textual SIL easier to read and has no effect on the generated DWARF.

<rdar://problem/28859432>
2018-06-26 18:07:04 -07:00
Davide Italiano
216c382213 [SILLocation] Mark this function as LLVM_NODISCARD to prevent misuses. 2018-05-25 16:34:07 -07:00
Sho Ikeda
03fbd4a6de [gardening][SIL] Replace typedef with using 2018-04-05 13:53:20 +09:00
Adrian Prantl
b4781f63ef Debug Info: Create artificial functions in a virtual file <compiler-generated>.
For the majority of artificial helper functions the filename is
actively misleading since it usually represents the file of the caller
that triggered the helper to be generated. Instead, this patch creates
a virtual filname `<compiler-generated>` to make it very obvious that
the function has not correspondence to any source code.

<rdar://problem/33809560>
2018-01-17 11:09:35 -08:00
Vedant Kumar
d60ff05265 Rename getEmptyLocation to getCompilerGeneratedLocation 2018-01-09 12:38:45 -08:00
Vedant Kumar
e33f3b663d [DebugInfo] Add a free helper to get empty locations, NFC 2018-01-08 17:59:16 -08:00
Adrian Prantl
5ea2d13f5e Improve the performance of IRGenDebugInfo
This commit changes how inline information is stored in SILDebugScope
from a tree to a linear chain of inlined call sites (similar to what
LLVM is using). This makes creating inlined SILDebugScopes slightly
more expensive, but makes lowering SILDebugScopes into LLVM metadata
much faster because entire inlined-at chains can now be cached. This
means that SIL is no longer preserve the inlining history (i.e., ((a
was inlined into b) was inlined into c) is represented the same as (a
was inlined into (b was inlined into c)), but this information was not
used by anyone.

On my late 2012 i7 iMac, this saves about 4 seconds when compiling the
RelWithDebInfo x86_64 swift standard library — or 40% of IRGen time.

rdar://problem/28311051
2017-04-05 08:33:55 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Adrian Prantl
4d1ae142c6 Remove the redundant DeclCtx field in SILFunction.
In all cases the DeclCtx field was supposed to be initialized from the
SILLocation of the function, so we can save one pointer per
SILFunction.

There is one test case change where a different (more precise)
diagnostic is being generated after this change.
2017-02-06 11:07:50 -08:00
Bob Wilson
37e7d1c627 Merge remote-tracking branch 'origin/master' into master-next 2017-01-08 17:07:46 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Bob Wilson
13da3fa8b1 Merge remote-tracking branch 'origin/master' into master-next 2016-12-04 18:16:09 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Bob Wilson
f10ae47b9f Merge remote-tracking branch 'origin/master' into master-next 2016-11-15 17:32:28 -08:00
Michael Gottesman
fd760080a8 [debug-info] Add an == operator to DebugLoc.
I am going to need this for some DI changes needed for rdar://28851920.

rdar://28851920
2016-10-29 16:39:03 -07:00
Bob Wilson
3fd92f82e8 Use StringRef in more places to match recent llvm changes.
llvm r283043 and possibly other recent changes switch to use StringRef
instead of char* pointers. Update Swift to match. In some cases, this is
a clear improvement. It would be good to assess the impact on memory use,
particularly for the Filename component of source locations.

Note that the change to SILLocation::isNull fixes an apparent bug where
the location was treated as null when the filename was *not* null.
2016-10-15 11:02:07 -07:00
Erik Eckstein
b871d45775 Small refactoring in SILLocation.
Needed for the upcoming commits.
2016-03-18 13:44:08 -07:00
Adrian Prantl
310b0433a9 Reapply "Serialize debug scope and location info in the SIL assembler language.""
This ireapplies commit 255c52de9f.

Original commit message:

Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 13:28:57 -08:00
Adrian Prantl
255c52de9f Revert "Serialize debug scope and location info in the SIL assembler language."
Temporarily reverting while updating the validation test suite.

This reverts commit c9927f66f0.
2016-02-26 11:51:57 -08:00
Adrian Prantl
c9927f66f0 Serialize debug scope and location info in the SIL assembler language.
At the moment it is only possible to test the effects that SIL
optimization passes have on debug information by observing the
effects of a full .swift -> LLVM IR compilation. This change enable us
to write targeted testcases for single SIL optimization passes.

The new syntax is as follows:

 sil-scope-ref ::= 'scope' [0-9]+
 sil-scope ::= 'sil_scope' [0-9]+ '{'
                 sil-loc
                 'parent' scope-parent
                 ('inlined_at' sil-scope-ref )?
               '}'
 scope-parent ::= sil-function-name ':' sil-type
 scope-parent ::= sil-scope-ref
 sil-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+

Each instruction may have a debug location and a SIL scope reference
at the end.  Debug locations consist of a filename, a line number, and
a column number.  If the debug location is omitted, it defaults to the
location in the SIL source file.  SIL scopes describe the position
inside the lexical scope structure that the Swift expression a SIL
instruction was generated from had originally. SIL scopes also hold
inlining information.

<rdar://problem/22706994>
2016-02-26 10:46:29 -08:00
Adrian Prantl
8e1d6c013b Make SILDebugLocation a value member of SILInstruction again.
The overhead of uniquing the locations in a Densemap isn't worth any of
the potential memory savings: While this adds an extra pointer and
unsigned to each SILInstruction, any extra memory is completely lost in
the noise (measured on a release -emit-ir build of the x86_64 stdlib).
This is not too surpising as the ratio between SILInstructions and unique
SILLocations is not very high and the DenseMap also needs space.

<rdar://problem/22706994>
2016-02-19 13:41:54 -08:00
Adrian Prantl
40c7a1abee Separate underlying storage and location kind in SILLocation and
remove the mixed concept that was SILFileLocation.
Also add support for a third type of underlying storage that will be used
for deserialized debug lcoations from textual SIL.

NFC

<rdar://problem/22706994>
2016-02-19 11:16:48 -08:00
Adrian Prantl
5dd6e6f5f4 Move the functionality to extract the debug location from a SILLocation
into SILLocation, since this will become useful for serialization.

NFC

<rdar://problem/22706994>
2016-02-09 11:58:15 -08:00
Jordan Rose
69fbc5b77b Get some files off of PointerLikeTypeTraitsFwdDecl.h 2016-02-06 11:22:28 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Gribenko
ac57add3a2 Merge pull request #504 from practicalswift/fix-typos-8
Fix typos (8 of 30)
2015-12-13 20:11:40 -08:00
practicalswift
f212b72dc8 Fix typo: correspondance → correspondence 2015-12-14 00:11:30 +01:00
practicalswift
2b6346c0bf Fix typo: artifically → artificially 2015-12-14 00:11:14 +01:00
John McCall
5fddd4a704 Remove the autorelease_return and strong_retain_autoreleased instructions.
There's a buggy SIL verifier check that was previously tautological,
and it turns out that it's violated, apparently harmlessly.  Since it
was already doing nothing, I've commented it out temporarily while
I figure out the right way to fix SILGen to get the invariant right.
2015-12-09 14:50:20 -08:00
Adrian Prantl
8ab1e2dd50 Unify debug scope and location handling in SILInstruction and SILBuilder.
The drivers for this change are providing a simpler API to SIL pass
authors, having a more efficient of the in-memory representation,
and ruling out an entire class of common bugs that usually result
in hard-to-debug backend crashes.

Summary
-------

SILInstruction

Old                   New
+---------------+     +------------------+    +-----------------+
|SILInstruction |     |SILInstruction    |    |SILDebugLocation |
+---------------+     +------------------+    +-----------------+
| ...           |     | ...              |    | ...             |
|SILLocation    |     |SILDebugLocation *| -> |SILLocation      |
|SILDebugScope *|     +------------------+    |SILDebugScope *  |
+---------------+                             +-----------------+

We’re introducing a new class SILDebugLocation which represents the
combination of a SILLocation and a SILDebugScope.
Instead of storing an inline SILLocation and a SILDebugScope pointer,
SILInstruction now only has one SILDebugLocation pointer. The APIs of
SILBuilder and SILDebugLocation guarantees that every SILInstruction
has a nonempty SILDebugScope.

Developer-visible changes include:

SILBuilder
----------

In the old design SILBuilder populated the InsertedInstrs list to
allow setting the debug scopes of all built instructions in bulk
at the very end (as the responsibility of the user). In the new design,
SILBuilder now carries a "current debug scope" state and immediately
sets the debug scope when an instruction is inserted.
This fixes a use-after-free issue with with SIL passes that delete
instructions before destroying the SILBuilder that created them.

Because of this, SILBuilderWithScopes no longer needs to be a template,
which simplifies its call sites.

SILInstruction
--------------

It is neither possible or necessary to manually call setDebugScope()
on a SILInstruction any more. The function still exists as a private
method, but is only used when splicing instructions from one function
to another.

Efficiency
----------

In addition to dropping 20 bytes from each SILInstruction,
SILDebugLocations are now allocated in the SILModule's bump pointer
allocator and are uniqued by SILBuilder. Unfortunately repeat compiles
of the standard library already vary by about 5% so I couldn’t yet
produce reliable numbers for how much this saves overall.

rdar://problem/22017421
2015-11-19 09:31:26 -08:00
Adrian Prantl
33f71c95a9 Simplify/Unify the constructors of SILLocation. (NFC) 2015-11-04 10:37:50 -08:00
Adrian Prantl
6baf5c629a Cleanup the comments in SILLocation. 2015-11-03 13:45:02 -08:00
Chris Lattner
95b7b4d5e4 rename CleanupLocation::getCleanupLocation -> CleanupLocation::get, NFC.
Swift SVN r26994
2015-04-04 22:56:01 +00:00
Doug Gregor
fdcbfcf5a2 Stop using LLVM_EXPLICIT.
It's gone from LLVM trunk, and all our compilers support it.

Swift SVN r25312
2015-02-16 17:39:03 +00:00
Dave Abrahams
ee145a1ac6 s/implicitely/implicitly/g
Correct a pervasive spelling error

Swift SVN r23774
2014-12-07 22:03:36 +00:00
Adrian Prantl
d3fcfc832d Handle toplevel locations in InlinedLocation. This fixes a crash that
with the unoptimized stdlib caught by the buildbots.

Swift SVN r22799
2014-10-16 16:27:15 +00:00
Adrian Prantl
4ccf572d4f Reapply r22739 using the new DebugLoc mechanism in SILLocation.
Change the SILLocations for enum element dispatches to make the line table
more consistent. emitEnumElementDispatch may be invoked several times so
it should use the location of the first pattern rather than TheSwitch.

Swift SVN r22782
2014-10-15 23:05:57 +00:00
Adrian Prantl
d1c9f71a73 Enhance SILLocation so it can hold separate locations for diagnostics
and debug info. Drop most of the special SILLocation handling from
IRGenDebugInfo and eliminate lots of redundant code.

Swift SVN r22781
2014-10-15 23:05:57 +00:00
Adrian Prantl
bb726461b0 Ensure that the line table for the new SIL-generated main function begins
with user code and that the boilerplate is counted towards the prologue.

<rdar://problem/18563763> Setting a breakpoint on "main" in a Swift program doesn't stop at user code

Swift SVN r22611
2014-10-09 02:15:00 +00:00
Joe Groff
cac5807ae2 SILGen: Emit "main" as a SIL function.
Eliminate the intermediate top_level_code function. Now that SIL is expressive enough to express a "main" function, there's no reason for it, and this eliminates a bunch of mystery code in IRGen to thunk from main to top_level_code by reaching for hardcoded symbol names. Demystify the special code for setting up C_ARGC and C_ARGV by having SILGen look for a transparent "_didEnterMain" hook in the stdlib and emit a call to it.

Swift SVN r22525
2014-10-05 04:13:24 +00:00
Anna Zaks
782fac1d6a [SIL Unreachability] Do not report false positives in single statement closures
(I suspect SILLocation annotation code in other places is not aware of isImplicit() AST flag...)

Swift SVN r22110
2014-09-19 01:40:03 +00:00
Chris Lattner
d473159814 Implement the start of a diagnostic to detect cases where inout aliasing violations are
introduced, as these are obvious miscompilations and clearly mystifying to our user base.

This is enough to emit diagnostics like this:

writeback_conflict_diagnostics.swift:58:70: error: inout writeback aliasing conflict detected on computed property 'c_local_struct_property'
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
                                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
writeback_conflict_diagnostics.swift:58:33: note: concurrent writeback occurred here
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

which isn't great, but is better than nothing (better wording is totally welcome!).

This doesn't handle subscripts (or many other kinds of logical lvalue) at all yet, so 
it doesn't handle the swift WTF case, but this is progress towards that.



Swift SVN r20297
2014-07-22 05:37:42 +00:00
Michael Gottesman
2eb34c35a4 [sil-inliner] Ensure that all special flags are propagated when we create a CleanupLocation, MandatoryInlinedLocation, or InlinedLocation from a SILLocation.
This corresponds to the fix I spoke of in r11595.

Swift SVN r11600
2013-12-23 06:35:38 +00:00
Michael Gottesman
b390ad4279 Fixed typo from 11456.
Swift SVN r11457
2013-12-19 00:27:29 +00:00
Michael Gottesman
dffa7fe5bf [sil-inliner] Add support for Stmt, Pattern ASTNodes to Inlined/MandatoryInlined Location as per my discussion with Anna.
Swift SVN r11456
2013-12-19 00:16:21 +00:00
Adrian Prantl
8b99609e94 relax assertion
Swift SVN r11096
2013-12-10 22:53:16 +00:00