Commit Graph

46 Commits

Author SHA1 Message Date
Emil Pedersen
0be63d0422 [DebugInfo] Return complete variable info from getVarInfo by default
getVarInfo() now always returns a variable with a location and scope.
To opt out of this change, getVarInfo(false) returns an incomplete variable.
This can be used to work around bugs, but should only really be used for
printing.

The complete var info will also contain the type, except for debug_values,
as its type depends on another instruction, which may be inconsistent if
called mid-pass.

All locations in debug variables are now also stripped of flags, to avoid
issues when comparing or hashing debug variables.
2024-05-10 16:12:56 -07:00
Nate Chandler
5ccec0e31c [NFC] SIL: Shortened member name.
Renamed "getUsesMoveableValueDebugInfo" to "usesMoveableValueDebugInfo".
Clarifies the predicate from "does the receiver have the
usesMoveableValueDebugInfo field set?" to "does the receiver use moveable
value debug info?".
2024-03-08 21:24:38 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Michael Gottesman
a569160f21 [sil] Refactor out the variable name inferer from MoveOnlyDiagnostics.cpp -> VariableNameUtils.
I am going to reuse this for TransferNonSendable. In the process I made a few
changes to make it more amenable to both use cases and used the current set of
tests that we have for noncopyable types to validate that I didn't break
anything.
2024-02-06 13:42:35 -08:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Joe Groff
9db359985d Emit updated debug info when inout parameters are consumed and reinitialized.
Change SILGen to emit the `debug_value` instruction using the original inout
parameter address, instead of the `mark_must_check` inserted for move-only
parameters, because code in the MoveOnlyAddressChecker did not expect to
find the debug_value anywhere but on the original address. Update move-only
diagnostics so that they pick up the declaration name for a memory location
from any debug_value instruction if there are more than one. rdar://109740281
2023-05-24 12:15:53 -07:00
Joe Groff
51f75c99a4 MoveOnlyAddressChecker: Reintroduce debug info for variables after reassignment.
After a value is consumed, we emit a `debug_value undef` to indicate that the
variable value is no longer valid to the debugger. However, once a value is
reassigned, it becomes valid again, so emit a `debug_value %original_address` to
reassociate the variable with the valid memory location. rdar://109218404
2023-05-18 15:08:59 -07:00
Michael Gottesman
ee451f0862 [move-only] If we have a noncopyable type on an alloc_stack/alloc_box/debug_value, set the [moveable_value_debuginfo] flag.
This still does not have the complete behavior that we want since we are not yet
inserting the debug_value undef to invalidate after performing moves.

NOTE: In printed SIL, I decided to make the flag implicit if we have a
noncopyable type. This is just to reduce the bloat in SIL. If one needs this
property for a copyable type though, it is mandatory.
2023-03-19 16:05:51 -07:00
Michael Gottesman
8d12f893c2 [sil] Add a moveable_value_debuginfo field to AllocBoxInst.
Just getting parsing/serialization to work. I haven't wired it up to anything.
2023-03-19 15:50:29 -07:00
Michael Gottesman
4a309575d7 [sil] Rename [moved] flag on debug_value/alloc_stack to moveable_value_debuginfo.
This is in preparation for wiring up debug info support for noncopyable
values. Originally this flag name made sense since it was set when we performed
consume operator checking. Now I am going to use it for noncopyable types as
well. I think the new name uses_moveable_value_debuginfo actually describes what
the flag is supposed to do, tell IRGen that the value may be moved since it
needs to use moveable value debug info emission.
2023-03-19 15:38:42 -07:00
Michael Gottesman
52236220e3 [debug-info] Add a helper getDiagnosticName that works for both DebugVarCarryingInst and VarDeclCarryingInst. 2023-02-17 16:04:46 -08:00
Michael Gottesman
cec4896615 [debug-info] Add a new super class of DebugVarCarryingInst called VarDeclCarryingInst.
I discovered when working with improving the debug output of the move only
address checker that I had a need for lightweight thing like
DebugVarCarryingInst but that only could vend a VarDecl (unlike
DebugVarCarryingInst which also can vend a SILDebugVariable). As an example,
this lets one write a high level API that uses the standard API to loop over a
bunch of instructions all that vend a VarDecl and construct a stringified path
component list.

rdar://105293841
2023-02-10 13:37:59 -08:00
Erik Eckstein
8ca0143279 Remove uses of std::iterator
It's deprecated in C++17
2022-11-14 09:35:40 +01:00
Michael Gottesman
640d5902e6 [debug-info] Implement a global dataflow that propagates debug info for async vars and clones the dbg info after funclet points.
The overall flow of the pass is:

1. We walk over the blocks summarizing the debug info instruction the blocks gen
as well as whether or not the block had an async funclet edge with in it.

2. We then perform a simple forward iterative optimistic dataflow using
intersection at merge points. At points where we find after merging that we have
a conflict and thus need to stop propagation, we insert a debug_value undef.

3. We then walk the CFG again visiting only blocks that we know had async
funclet edges. We then walk each said block from top to bottom starting with the
propagating gen information and updating as we go, dumping the current set of
debug_info we are tracking after each coroutine funclet boundary.

rdar://85020571
2022-05-05 14:16:51 -07:00
Michael Gottesman
5acbeed5a4 [debug-info-canonicalization] Add support for propagating debug info from alloc_stack. 2022-03-22 12:34:15 -07:00
Michael Gottesman
edbe4db7af [move-function] Add initial debug info support to move checker passes.
Specifically in this commit we:

1. Add support to the move checkers for marking alloc_stack that are moved or
the debug_value of values that are moved with the [moved] flag. In a subsequent
PR, I am going to add support in IRGen for emitting llvm.dbg.addr instead of
llvm.dbg.declare for such variables. This will ensure that debug info for values
that aren't moved get the same codegen.

2. I changed the move checkers to begin emitting debug_value undef at the move
site. This ensures that after that point the moved value will be unavailable in
the debugger.

3. I also found a small bug that was around terminators that was exposed by some
of my tests.

What is not in this patch:

1. IRGen part of this patch.
2. DebugInfoCanonicalization that pushes debug_info into coroutine func lets to
avoid issues with Swift's coroutine splitting at the LLVM level.

rdar://85020571
2022-02-14 18:41:43 -08:00
Michael Gottesman
ef23e1fcca [debug-utils] Add a new utility getDebugVarName to translate a SILValue to a potential debug name.
If we don't find a name, we just return unknown so code that uses this still
gets valid output.
2021-12-02 12:02:11 -08:00
Michael Gottesman
e5d0f386e4 [moveOnly] Add a new experimental move only checker that checks noImplicitCopy variables.
NOTE: This is only available when the flag -enable-experimental-move-only. There
are no effects when the flag is disabled.

The way that this works is that it takes advantage of the following changes to
SILGen emission:

* When SILGen initializes a let with NoImplicitCopyAttribute, SILGen now emits
a begin_borrow [lexical] + copy + move_only. This is a pattern that we can check
and know that we are processing a move only value. When performing move
checking, we check move_only as a move only value and that it isn't consumed
multiple times.

* The first point works well for emitting all diagnostics except for
initializing an additional let var. To work around that I changed let
initialization to always bind to an owned value to a move of that owned
value. There is no semantic difference since that value is going to be consumed
by the binding operation anyways so we effectively just move the cleanup from
the original value we wanted to bind to the move. We still then actually borrow
the new let value with a begin_borrow [lexical] for the new let value. This
ensures that an initialization of a let value appears to be a consuming use to
the move only value checker while ensuring that the value has a proper
begin_borrow [lexical].

Some notes on functionality:

1. This attribute can only be applied to local 'let'.

2. "print" due to how we call it today with a vararg array is treated as a
   consuming use (unfortunately).

3. I have not added the builtin copy operator yet, but I recently added a _move
   skeleton attribute so one can end the lifetimes of these values early.

4. This supports all types that are not address only types (similar to
   _move). To support full on address only types we need opaque values.

rdar://83957088
2021-10-28 11:32:22 -07:00
Min-Yih Hsu
343d842394 [SIL][DebugInfo] PATCH 3/3: Deprecate debug_value_addr SIL instruciton
This patch removes all references to DebugValueAddrInst class and
debug_value_addr instruction in textual SIL files.
2021-08-31 12:01:04 -07:00
Min-Yih Hsu
9a8f2ed642 [SILOptimizer][DebugInfo] Preliminary support for DIExpression in SROA and Mem2Reg
SROA and Mem2Reg now can leverage DIExpression -- op_fragment, more
specifically -- to generate correct debug info for optimized SIL. Some
important highlights:
 - The new swift::salvageDebugInfo, similar to llvm::salvageDebugInfo,
   tries to restore / transfer debug info from a deleted instruction.
   Currently I only implemented this for store instruction whose
   destination is an alloc_stack value.
 - Since we now have source-variable-specific SIL location inside a
   `debug_value` instruction (and its friends), this patch teaches
   SILCloner and SILInliner to remap the debug scope there in addition
   to debug scope of the instruction.
 - DCE now does not remove `debug_value` instruction whose associating
   with a function argument SSA value that is not used elsewhere. Since
   that SSA value will not disappear so we should keep the debug info.
2021-08-05 17:27:45 -07:00
Saleem Abdulrasool
25f437e17d mark some switches as covered (NFCI)
Unfortunately, MSVC does not detect covered switches as clang.  Mark
some of the switches as covered to avoid an unnecessary warning from
MSVC.
2021-06-05 15:30:25 -07:00
Michael Gottesman
d9f2c1ed0f [debug-info] Define DebugVarCarryingInst, a light abstraction on top of instructions that carry information about a specific debug variable.
This allows one to write high level code over the set of such instructions with
greater correctness by using exhaustive switches, methods, and keeping it light
weight by using *, -> operators to access functionality from the underlying
instruction when needed.
2021-03-30 18:57:42 -07:00
Michael Gottesman
471c7479c7 [debug-utils] Split deleteAllDebugUses(ValueBase *) into SILValue and SILInstruction variants.
The SILInstruction variant calls the SILValue version for each of its results.
2019-09-30 10:33:52 -07:00
moatom
2e95a0d265 Fix include guards 2019-06-02 12:10:43 +09:00
Andrew Trick
ece096d91e Fix eraseFromParentWithdebugInsts to call a callback.
The recursivelyDeleteTriviallyDeadInstructions utility takes a
callBack to be called for every deleted instruction. However, it
wasn't passing this callBack to eraseFromParentWithdebugInsts. The
callback was used to update an iterator in some cases, so not calling
it resulted in iterator invalidation.

Doing this also cleans up the both APIs:
recursivelyDeleteTriviallyDeadInstructions and eraseFromParentWithdebugInsts.
2019-05-06 17:23:08 -07:00
Andrew Trick
bd28b0ea1b SILCloner and SILInliner rewrite.
Mostly functionally neutral:
- may fix latent bugs.
- may reduce useless basic blocks after inlining.

This rewrite encapsulates the cloner's internal state, providing a
clean API for the CRTP subclasses. The subclasses are rewritten to use
the exposed API and extension points. This makes it much easier to
understand, work with, and extend SIL cloners, which are central to
many optimization passes. Basic SIL invariants are now clearly
expressed and enforced. There is no longer a intricate dance between
multiple levels of subclasses operating on underlying low-level data
structures. All of the logic needed to keep the original SIL in a
consistent state is contained within the SILCloner itself. Subclasses
only need to be responsible for their own modifications.

The immediate motiviation is to make CFG updates self-contained so
that SIL remains in a valid state. This will allow the removal of
critical edge splitting hacks and will allow general SIL utilities to
take advantage of the fact that we don't allow critical edges.

This rewrite establishes a simple principal that should be followed
everywhere: aside from the primitive mutation APIs on SIL data types,
each SIL utility is responsibile for leaving SIL in a valid state and
the logic for doing so should exist in one central location.

This includes, for example:
- Generating a valid CFG, splitting edges if needed.
- Returning a valid instruction iterator if any instructions are removed.
- Updating dominance.
- Updating SSA (block arguments).

(Dominance info and SSA properties are fundamental to SIL verification).

LoopInfo is also somewhat fundamental to SIL, and should generally be
updated, but it isn't required.

This also fixes some latent bugs related to iterator invalidation in
recursivelyDeleteTriviallyDeadInstructions and SILInliner. Note that
the SILModule deletion callback should be avoided. It can be useful as
a simple cache invalidation mechanism, but it is otherwise bug prone,
too limited to be very useful, and basically bad design. Utilities
that mutate should return a valid instruction iterator and provide
their own deletion callbacks.
2018-10-08 19:30:09 -07:00
Davide Italiano
b4d563802b [SILInstruction] Introduce isDebugInstruction().
This is a property of an instruction and should be a member
function of `SILInstruction` and not a free function in
`DebugUtils`. Discussed with Adrian.
2018-04-11 10:14:21 -07:00
Michael Gottesman
88bc490380 [func-sig-opts] hasNonTrivialNonDebugUse => hasNonTrivialNonDebugTransitiveUsers and move to DebugUtils.
I am getting rid of FunctionSignatureOptUtils. It is only used by
FunctionSignatureOpts, so it should either be a local utility file whose header
lives in ./lib or integrated into FunctionSignatureOpts. Beyond this utility
function (which seems like a generally useful thing that should be in
DebugUtils), the only other thing left in FunctionSignatureOptUtils is part of
the heuristic of FunctionSignatureOpts. It should really be in that file.

rdar://38196046
2018-04-07 10:06:48 -07:00
Davide Italiano
dfaf133d27 [LoadableByAddress] Fix debug info holes when expanding alloc_stack.
<rdar://problem/36876376>
2018-03-28 11:54:03 -07:00
Davide Italiano
47115e6dbd [SILVerifier] Loosen verification for debug info scopes holes.
We should also skip debug info as they don't really are lowered
to anything real. Add an helper so that we can use it in passes
as well.
2018-03-27 13:54:57 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Andrew Trick
4256112150 AddressLowering: fix handling of result tuples. 2017-02-16 11:04:42 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
Xin Tong
e2c0990851 Rename hasNoUsesExceptDebug to onlyHaveDebugUses. The double negation logic is
harder to understand. NFC.
2016-02-10 14:46:09 -08:00
Erik Eckstein
5a53b31f57 SIL: remove use-iteration functions from SILValue.
They are not needed anymore. NFC.
2016-01-25 15:00:49 -08:00
Erik Eckstein
f2c0283437 Simplify DebugUtils
With the changes in SILValue there is no need for template functions in DebugUtils anymore.
2016-01-21 16:04:30 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Arnold Schwaighofer
6287f13dd2 Fix getSingleNonDebugUser to really return a single non debug user. 2015-12-14 12:02:33 -08:00
Arnold Schwaighofer
dee05869ff DebugUtils: Add an api to get the single non debug user 2015-12-08 07:34:25 -08:00
Nadav Rotem
7192b28f49 Fix another iterator invalidation bug. 💥 2015-11-11 22:38:00 -08:00
Nadav Rotem
0a0136d6fb Move deleteAllDebugUses into DebugUtils.h
Swift SVN r32508
2015-10-08 01:13:54 +00:00
Mark Lacey
406fe20129 Add forward declarations for SILInstruction.
Remove the include of SILInstruction.h in a couple places since it is
not necessary and forces more recompilation than necessary when edits
are made to SILInstruction.h.

Swift SVN r32091
2015-09-19 02:48:06 +00:00
Dmitri Hrybenko
37a4335b88 Replace swift::Range with llvm::iterator_range
Due to inreased use of llvm::make_range in LLVM headers and ADL for
types defined in the swift namespace, some of the LLVM headers started
to trigger ambiguity errors between llvm::make_range and
swift::make_range.

Swift SVN r29700
2015-06-25 22:01:39 +00:00
Erik Eckstein
3092f3c15f Document the utility functions for handling debug_value instructions, introduced in r28872.
Swift SVN r29064
2015-05-27 10:49:55 +00:00
Erik Eckstein
c7a245ec53 SIL: Add utility functions to handle debug_value/debug_value_addr instructions.
Swift SVN r28871
2015-05-21 13:20:24 +00:00