Commit Graph

267 Commits

Author SHA1 Message Date
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Michael Gottesman
ea1f804207 [semantic-sil] Eliminate ValueOwnershipKind::Any from SILPHIArguments in Semantic SIL.
Most of this involved sprinkling ValueOwnershipKind::Owned in many places. In
some of these places, I am sure I was too cavalier and I expect some of them to
be trivial. The verifier will help me to track those down.

On the other hand, I do expect there to be some places where we are willing to
accept guaranteed+trivial or owned+trivial. In those cases, I am going to
provide an aggregate ValueOwnershipKind that will then tell SILArgument that it
should disambiguate using the type. This will eliminate the ackwardness from
such code.

I am going to use a verifier to fix such cases.

This commit also begins the serialization of ValueOwnershipKind of arguments,
but does not implement parsing of value ownership kinds. That and undef are the
last places that we still use ValueOwnershipKind::Any.

rdar://29791263
2017-01-10 20:05:23 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
4e8ff35df5 [semantic-sil] Add ValueOwnershipKind field to SILPHIArgument and split Argument creation methods into one for SILPHIArgument and another for SILFunctionArgument.
We preserve the current behavior of assuming Any ownership always and use
default arguments to hide this change most of the time. There are asserts now in
the SILBasicBlock::{create,replace,insert}{PHI,Function}Argument to ensure that
the people can only create SILFunctionArguments in entry blocks and
SILPHIArguments in non-entry blocks. This will ensure that the code in tree
maintains the API distinction even if we are not using the full distinction in
between the two.

Once the verifier is finished being upstreamed, I am going to audit the
createPHIArgument cases for the proper ownership. This is b/c I will be able to
use the verifier to properly debug the code. At that point, I will also start
serializing/printing/parsing the ownershipkind of SILPHIArguments, but lets take
things one step at a time and move incrementally.

In the process, I also discovered a CSE bug. I am not sure how it ever worked.
Basically we replace an argument with a new argument type but return the uses of
the old argument to refer to the old argument instead of a new argument.

rdar://29671437
2016-12-18 14:48:35 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Joe Groff
b6823b930b SIL: Change SILType::subst to be SubstitutionMap-based.
This simplifies the SILType substitution APIs and brings them in line with Doug and Slava's refactorings to improve AST-level type substitution. NFC intended.
2016-12-14 14:33:32 -08:00
Michael Gottesman
38ec08f45f [gardening] Standardize SILBasicBlock successor/predecessor methods that deal with blocks rather than the full successor data structure to have the suffix 'Block'.
This was already done for getSuccessorBlocks() to distinguish getting successor
blocks from getting the full list of SILSuccessors via getSuccessors(). This
commit just makes all of the successor/predecessor code follow that naming
convention.

Some examples:

getSingleSuccessor() => getSingleSuccessorBlock().
isSuccessor() => isSuccessorBlock().
getPreds() => getPredecessorBlocks().

Really, IMO, we should consider renaming SILSuccessor to a more verbose name so
that it is clear that it is more of an internal detail of SILBasicBlock's
implementation rather than something that one should consider as apart of one's
mental model of the IR when one really wants to be thinking about predecessor
and successor blocks. But that is not what this commit is trying to change, it
is just trying to eliminate a bit of technical debt by making the naming
conventions here consistent.
2016-11-27 12:32:51 -08:00
Michael Gottesman
96837babda Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2016-11-25 09:17:21 -06:00
Michael Gottesman
bf6920650c [gardening] Drop BB from all argument related code in SILBasicBlock.
Before this commit all code relating to handling arguments in SILBasicBlock had
somewhere in the name BB. This is redundant given that the class's name is
already SILBasicBlock. This commit drops those names.

Some examples:

getBBArg() => getArgument()
BBArgList => ArgumentList
bbarg_begin() => args_begin()
2016-11-25 01:14:36 -06: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
Michael Gottesman
a8c4cc60e8 [gardening] Rename ValueBase::getParentBB() => getParentBlock(). 2016-11-14 00:39:47 -08:00
practicalswift
ae5542609e [gardening] Fix accidental \t:s 2016-10-13 20:24:09 +02:00
Joe Shajrawi
b05d3c2985 Merge pull request #5138 from shajrawi/copy_addr_to_moves
Comment on why we can't replace copy_addr instructions with moves in arc-inert blocks
2016-10-11 16:50:50 -07:00
Joe Shajrawi
13b7bd5775 Add a discussion that sums-up why we can’t replace copy_addr with moves in ARC-inert BBs 2016-10-11 15:54:33 -07:00
Roman Levenstein
20a6d35985 Fix a case of ArrayRef capturing compiler temps.
Fixes rdar://28684618
2016-10-08 17:50:09 -07:00
Joe Shajrawi
52d90ab0d0 [SR-2512] Ignore duplicate conditions when optimizing switch statement 2016-09-12 15:39:13 -07:00
Michael Gottesman
ac3024292b [simplify-cfg] When moving cond_fail to preds, do not bail early.
This commit fixes a bug where we were not checking that all predecessors had the
cond_fail block as its only successor. This occured since we were bailing early
when we saw a constant. So if we saw a predecessor with a constant before a
predecessor that had multiple successors, we would optimize even though we would
be introducing an extra cond_fail along a path.

I added a new utility pass to test this code since so much is going on in
SimplifyCFG that it is difficult to construct a test case running the full
pass.

Really this code should be in a different pass (properly SIL Code Motion TBH).
But for now, this commit just fixes the bug.

rdar://26904047
2016-07-17 23:31:53 -07:00
Erik Eckstein
4c17897285 SimplifyCFG: fix crash in case an enum payload is an enum
fixes rdar://problem/26251856
2016-05-12 23:12:13 -07:00
Erik Eckstein
db288e958b SimplifyCFG: fix a crash in debug output 2016-05-12 08:38:38 -07:00
Erik Eckstein
b3e81a084f SimplifyCFG: unpack enum arguments.
As we already do for structs and tuples.
If all incoming values are enum instructions and the only use is an unchecked_enum_data, then we can replace the argument with the enum payload itself.
2016-05-05 10:34:08 -07:00
Erik Eckstein
380ded8151 SimplifyCFG: debug dump the function name at the beginning of the pass 2016-05-05 10:34:08 -07:00
Erik Eckstein
f24e23660d SimplifyCFG: don't jump thread if the condition is an undef.
Uses of undef can be in a different function. This may result in modifying another function.
A test is included in a following commit.
2016-05-05 10:34:08 -07:00
Erik Eckstein
512cc62e43 SimplifyCFG: recalculate loop header information if a loop header block is jump threaded. 2016-05-05 10:34:08 -07:00
Erik Eckstein
9577aa698a fix comment 2016-05-05 10:34:08 -07:00
Erik Eckstein
7f71e4c6fe SimplifyCFG: improve debug logging 2016-05-05 10:34:08 -07:00
Erik Eckstein
53bb3e8ea1 SimplifyCFG: improve switch_enum simplification.
Figure out the enum case if an enum value is dominated by a switch_enum and use this info for a subsequent switch_enum to be simplified.

This change partly recovers the ClosedRange-regression.
rdar://problem/25933907
2016-04-29 10:57:01 -07:00
practicalswift
872070900d [gardening] Consistent formatting of STATISTIC(…, "…"); 2016-04-09 23:51:23 +02:00
Mark Lacey
a7eb7b10d9 Fix typo in comment. 2016-03-14 16:18:00 -07:00
Ben Langmuir
cf4498e6cf Mark a couple of local sil-optimizer functions as static NFC 2016-03-11 13:34:23 -08:00
Michael Gottesman
bb15808554 Convert some trivial std::count_if invocations on ranges to use the provided range adaptor. 2016-03-08 14:58:13 -08:00
Mark Lacey
4f2f993c68 Fix use-after-free in SimplifyCFG's block argument splitter.
We were creating new uses of an argument just prior to erasing it from
the block argument list.

We need to replace references to that value in the side structure we
generate with references to the new value that we're replacing it with.

Fixes SR-884 / rdar://problem/25008398.
2016-03-07 23:22:34 -08:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08: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
Xin Tong
84a6ff1d98 And lastly rename NewProjection to Projection. This is a NFC. rdar://24520269 2016-02-09 22:20:10 -08:00
Xin Tong
0258e8e816 Migrate to use new projection for SimplifyCFG. This should be a NFC.
This is part of rdar://24520269
2016-02-06 08:27:05 -08:00
Erik Eckstein
8520120121 SimplifyCFG: don't recalculate the dominator tree for each jump threaded checked_cast_br instruction.
This is done by splitting the transformation into an analysis phase and a transformation phase (which does not use the dominator tree anymore).
The domintator tree is recalucated once after the whole function is processed.

This change eventually solves the compile time problem of rdar://problem/24410167.
2016-02-02 17:46:32 -08:00
Erik Eckstein
3c6c48c4bf SimplifyCFG: simplify the switch_enum -> select_enum conversion.
The main intention for this change is to eliminate the use of the post/dominator trees in this transformation.
These were re-calculated on every conversion which caused long compile times for functions with lot of switch_enum instructions: rdar://problem/24410167

Beside that, the code for collecting the target-block's predecessors is now simpler. It's not necessary to handle arbitrary control flow pathes because jump threading is simplifying the CFG anyway.

Now SimplifyCFG does not use the PostDominanceAnalysis anymore.
2016-02-01 13:32:55 -08:00
Xin Tong
ff8c9e4a6f Fix a logic error in SimplifyCFG. isReachable is only used as part of NDEBUG. 2016-01-27 14:06:53 -08:00
Erik Eckstein
74d44b74e7 SIL: remove SILValue::getDef and add a cast operator to ValueBase * as a repelacement. NFC. 2016-01-25 15:00:49 -08:00
Erik Eckstein
d3c975391f SIL: remove dump and print from SILValue
If you want to dump a SILValue from the debugger, use Value->dump()
2016-01-25 15:00:49 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -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
b745691a38 SIL refactoring: Move some functions out of SILValue and Operand
SILValue.h/.cpp just defines the SIL base classes. Referring to specific instructions is a (small) kind of layering violation.
Also I want to keep SILValue small so that it is really just a type alias of ValueBase*.
NFC.
2016-01-25 10:37:03 -08:00
Erik Eckstein
ec172cde5b Remove SILValue::replaceAllUsesWith.
It's not needed anymore because we can use ValueBase::replaceAllUses
2016-01-21 16:04:30 -08:00
Erik Eckstein
2db6f3d213 SIL: remove multiple result values from SILValue
As there are no instructions left which produce multiple result values, this is a NFC regarding the generated SIL and generated code.
Although this commit is large, most changes are straightforward adoptions to the changes in the ValueBase and SILValue classes.
2016-01-21 10:30:31 -08:00
Michael Gottesman
e25cd8860c Remove all uses of ilist_node::getNextNode() and ilist_node::getPrevNode() in favor of just using iterators.
This change is needed for the next update to ToT LLVM. It can be put
into place now without breaking anything so I am committing it now.

The churn upstream on ilist_node is neccessary to remove undefined
behavior. Rather than updating the different ilist_node patches for the
hacky change required to not use iterators, just use iterators and keep
everything as ilist_nodes. Upstream they want to eventually do this, so
it makes sense for us to just do it now.

Please do not introduce new invocations of
ilist_node::get{Next,Prev}Node() into the tree.
2016-01-19 14:44:58 -06:00
Xin Tong
f5a77cd5ad Remove release instructions in non-arc-inert termination block. rdar://24011383 2016-01-14 15:37:10 -08:00
Michael Gottesman
5b1ebe12a9 Remove the case 'Invalid' from the TermKind enum and just use an unreachable in the ValueKind -> TermKind switch instead.
In all of the cases where this is being used, we already immediately perform an
unreachable if we find a TermKind::Invalid. So simplify the code and move it
into the conversion switch itself.
2016-01-11 15:44:05 -08:00
Michael Gottesman
24bd1e3974 Remove variable that is written to but never read. Found by the clang static analyzer. 2016-01-08 19:28:43 -08:00