Commit Graph

159 Commits

Author SHA1 Message Date
Graydon Hoare
cc16ddfd13 Revert "[SILOptimizer] Don't diagnose infinite recursion if a branch terminates (#19724)"
This reverts commit e94450e840.

rdar://45080912
2018-10-07 23:54:33 -07:00
Harlan
e94450e840 [SILOptimizer] Don't diagnose infinite recursion if a branch terminates (#19724)
This patch augments the infinite recursion checker to not warn if a
branch terminates, but still warns if a branch calls into something with
`@_semantics("arc.programtermination_point")`. This way, calling `fatalError`
doesn't disqualify you for the diagnostic, but calling `exit` does.

This also removes the warning workaround in the standard library, and
annotates the internal _assertionFailure functions as
`programtermination_point`s, so they get this treatment too.
2018-10-05 19:15:26 -07:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Michael Gottesman
2d6106aaa7 [sil] Add convenience method TermInst::getSuccessorBlockArguments().
This convenience API enables one to iterate over the array of arguments of each
successor of the terminator.

To implement this I needed to implement SILBasicBlock::getPHIArguments(), so I
also implemented SILBasicBlock::getFunctionArguments().

rdar://44667493
2018-09-21 10:01:35 -07:00
John McCall
512e55683e Make it easy to create a SILBasicBlock immediately before a target block.
Also, make "after" requests explicit in the API.
2018-08-18 12:36:36 -04:00
swift-ci
b966d3fbc1 Merge remote-tracking branch 'origin/master' into master-next 2018-05-07 08:29:22 -07:00
Jordan Rose
5bf9b9ac76 [SIL] Avoid std::function in transform-iterators
In a non-rigorous test, this change shaves off 20% of the time spent
in SIL optimizations for the standard library in a +Asserts build.
(Admittedly the wins for a no-asserts build will be much lower because
SILInstructionResultArray has a bunch of assertions in its
constructor.)
2018-05-04 17:48:52 -07:00
Bob Wilson
9dc02e67a2 master-next: Stop using ilist_default_traits
LLVM r330736 removed ilist_default_traits. Apparently it is not needed
and ilist_node_traits works just as well.
2018-04-25 22:44:58 -07:00
swift-ci
3e53228828 Merge remote-tracking branch 'origin/master' into master-next 2018-03-28 15:09:15 -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
Bob Wilson
f9497f5649 master-next: Update phi iteration for the LLVM SSAUpdater change in r321783
This replaces the previous solution that requires non-upstream changes
to LLVM.
2018-01-03 19:08:49 -08:00
Michael Gottesman
7819c4d41a [sil] Add const to int SILBasicBlock::getDebugId().
This is a read only function. This just allows one to call it in more places.

rdar://36032876
2017-12-19 10:10:12 -08:00
Michael Gottesman
2f1ebf3c51 [pred-memopt] Provide normal succ manipulation methods on TermInst instead of SILBasicBlock.
I am doing this for a few different reasons:

1. The code for manipulating successors was partially in TermInst (with
SILBasicBlock delegating to TermInst) and partly in SILBasicBlock itself. It
makes more sense to just be consistent and move all said functionality into
TermInst and just always delegate to SILBasicBlock.

2. I am preparing an API around gathering all critical edges. All of the
critical edge breaking APIs to take a TermInst. I wanted to use some of the
successor APIs, only to discover that we were not delegating to TermInst.  By
moving said functionality onto TermInst itself and delegating, we have it in
both places.

rdar://31521023
2017-11-11 11:27:42 -08: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
Arnold Schwaighofer
3edcd3008d SILBasicBlock: Add moveTo method 2017-09-06 07:24:19 -07:00
Arnold Schwaighofer
1bc5fb193b SIL: Add a utility function to SILBasicBlock to delete its instructions 2017-09-06 07:24:19 -07:00
Erik Eckstein
1ab582e121 SIL: A new representation of static initializers for global variables.
Static initializers are now represented by a list of literal and aggregate instructions in a SILGlobalVariable.
For details see SIL.rst.

This representation is cleaner than what we did so far (point to the initializer function and do some pattern matching).

One implication of that change is that now (a subset of) instructions not necessarily have a parent function.
Regarding the generated code it's a NFC.
Also the swift module format didn't change because so far we don't serializer global variables.
2017-08-23 09:15:01 -07:00
Jordan Rose
c22168d02d [SIL] Implement a very simple isLegalToHoistInto for llvm::LoopInfo.
I'm not a SIL author, so it's likely that this could be improved,
but I think this is closest to the old LLVM behavior.
2017-06-23 12:49:49 -07:00
Michael Gottesman
a11fceb635 [gardening] Remove unneeded method addNodeToList on ilist_traits<SILBasicBlock>.
addNodeToList only needs to be implemented to override the default callback
behavior of ilist_trait_defaults<SILBasicBlock>.  This implmentation in
ilist_traits<SILBasicBlock> is exactly the same as the default callback so is
unnecessary.
2017-06-06 10:12:37 -07:00
Michael Gottesman
e11daa8ddf [upstream-update] Do not use succ_iterator in GraphTraits. Use succblock_iterator instead.
rdar://31790907
2017-04-26 16:50:57 -07:00
Michael Gottesman
913920c93b [sil] Rename SILSuccessorIterator -> SILSuccessor::pred_iterator.
This iterator is not actually a SILSuccessorIterator since it is not iterating
over the "successors" of a block. Instead it is used to given the head of a CFG
edge, iterate over the CFG edge's predecessors using the double linked list
stored inside SILSuccessor.

This rename/refactor ties SILSuccessor closer to SILSuccessorIterator and makes
it clear what we are actually iterating over.
2017-04-26 13:32:59 -07:00
Andrew Trick
2eb6d48b1c [AccessMarker] Fix a reverse instruction iterator.
I reversed this loop's direction over the instruction list and forgot to change
the order of erasing an instruction with respect to advancing the iterator.

Thankfully ASAN is far smarter than I.

Converting between forward/reverse iterators makes the loop unreadable.
Add an iterator return value to BasicBlock::erase(SILInstruction*).
2017-04-10 14:08:59 -07:00
Andrew Trick
7ea54c8927 SILPrintContext: support for printing consistent block numbers. 2017-04-05 19:59:15 -07:00
Michael Gottesman
79b225ffa8 [silgen] Fix up EnumElementPatternInitialization::emitEnumMatch to use ownership.
This commit does a few things:

1. It uses SwitchEnumBuilder so we are not re-inventing any wheels.
2. Instead of hacking around not putting in a destroy for .None on the fail
pass, just *do the right thing* and recognize that we have a binary case enum
and in such a case, just emit code for the other case rather than use a default
case (meaning no cleanup on .none).

rdar://31145255
2017-03-29 15:36:41 -07:00
Michael Gottesman
ed67bf9f21 [ownership-verifier] Teach the ownership verifier how to handle unreachable code.
There are a few different use cases here:

1. In Raw SIL, no return folding may not have been run yet implying that a call
to a no-return function /can/ have arbitrary control flow after it (consider
mandatory inlined functions). We need to recognize that the region of code that
is strictly post dominated by the no-return function is "transitively
unreachable" and thus leaking is ok from that point. *Footnote 1*.

2. In Canonical and Raw SIL, we must recognize that unreachables and no-return
functions constitute places where we are allowed to leak.

rdar://29791263

----

*Footnote 1*: The reason why this is done is since we want to emit unreachable
code diagnostics when we run no-return folding. By leaving in the relevant code,
we have preserved all of the SILLocations on that code allowing us to create
really nice diagnostics.
2017-02-13 16:36:01 -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
Hugh Bellamy
4dfa6389b0 Introduce and use SWIFT_DELETE_OPERATOR_DELETED 2017-01-16 22:05:27 +00:00
Slava Pestov
5c0afe93bc Merge pull request #5954 from hughbe/sil-msvc
Fix errors and warnings building swift/SIL on Windows using MSVC
2017-01-11 15:41:51 -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
Michael Gottesman
5dea7ea07f [semantic-sil] Move ValueOwnershipKind -> SILArgument and have subclasses pass in said value.
This in the case of insertFunctionArgument requires a ValueOwnershipKind to be
specified since we use that for transformations of function argument lists that
are only correct after the transformation is complete. This only occurs in
FunctionSignatureOptimizations.

On the other hand, createFunctionArgument is only used to construct completely
new argument lists, so we can instead just rely on the function we are in rather
than require the user to pass it in.

rdar://29791263
2017-01-10 20:04:41 -08:00
Hugh Bellamy
36100bf21c Fix errors and warnings building swift/SIL on Windows using MSVC 2017-01-09 09:11:20 +00:00
Michael Gottesman
0f1b8bbfda [semantic-sil] Make a insertFunctionArgument helper method private.
There is no reason to allow for unnecessary APIs to be exposed since people will
then use them.
2017-01-08 00:22:54 -08:00
Michael Gottesman
f3603c4b87 [semantic-sil] Remove SILBasicBlock::replaceFunctionArgument. It is dead. 2017-01-08 00:22:54 -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
Michael Gottesman
19f0f6e686 [semantic-sil] Reify the split in SILArgument in between function and block arguments via subclasses.
For a long time, we have:

1. Created methods on SILArgument that only work on either function arguments or
block arguments.
2. Created code paths in the compiler that only allow for "function"
SILArguments or "block" SILArguments.

This commit refactors SILArgument into two subclasses, SILPHIArgument and
SILFunctionArgument, separates the function and block APIs onto the subclasses
(leaving the common APIs on SILArgument). It also goes through and changes all
places in the compiler that conditionalize on one of the forms of SILArgument to
just use the relevant subclass. This is made easier by the relevant APIs not
being on SILArgument anymore. If you take a quick look through you will see that
the API now expresses a lot more of its intention.

The reason why I am performing this refactoring now is that SILFunctionArguments
have a ValueOwnershipKind defined by the given function's signature. On the
other hand, SILBlockArguments have a stored ValueOwnershipKind. Rather than
store ValueOwnershipKind in both instances and in the function case have a dead
variable, I decided to just bite the bullet and fix this.

rdar://29671437
2016-12-18 01:11:28 -08:00
Bob Wilson
ae3db7c88e Update for llvm r281167: changes to ilist_iterator template arguments.
(cherry picked from commit 97e415ce2a)
2016-12-01 10:47:07 -08:00
Bob Wilson
2c21ef586d Update to match llvm r279473: remove ilist_*sentinel_traits.
(cherry picked from commit 391e7d8b60)
2016-12-01 10:46:38 -08:00
Bob Wilson
26a62b912a Update to match llvm r278513: share code for embedded sentinel traits.
Nothing at all should be changing here, this is just rearranging code.

(cherry picked from commit 9964697f22)
2016-12-01 10:42:59 -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
6a50566a75 [gardening] Use proper doxygen style by inserting a newline between brief and longer comment.
Also a little bit of copy editing.
2016-11-27 11:58:20 -08:00
Michael Gottesman
804df7cac9 [gardening] Standardize a bit of code style. NFC.
In this file, by and large we use 'Type *'.

This file converts a couple of places where we use 'Type*' => 'Type *'.
2016-11-27 11:58:20 -08:00
Michael Gottesman
edce501b71 [gardening] Eliminate unneeded 'public' from inheritance declaration of a struct.
structs always inherit publicly.
2016-11-27 11:58:20 -08:00
Michael Gottesman
529eec30b7 [gardening] Use const_cast rather than implement SILBasicBlock::getSingleSuccessor() twice for const/non-const. 2016-11-27 11:58:20 -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
a998d98924 [gardening] SILBasicBlock::splitBasicBlock() => *::split().
The BasicBlock suffix is redundant.
2016-11-25 01:14:43 -06:00
Michael Gottesman
e936de7b04 [gardening] 0 => nullptr. NFC. 2016-11-25 01:14:41 -06:00
Michael Gottesman
c3d5ace299 [gardening] Move SILBasicBlock::dropAllReferences() out of the argument list manipulation section.
I am not sure why it was put here originally, but I believe it is still there
due to bitrot.
2016-11-25 01:14:40 -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
Michael Gottesman
e42bf07af4 [gardening] Always create SILBasicBlocks via SILFunction::createBasicBlock.
This eliminates all inline creation of SILBasicBlock via placement new.

There are a few reasons to do this:

1. A SILBasicBlock is always created with a parent function. This commit
formalizes this into the SILBasicBlock API by only allowing for SILFunctions to
create SILBasicBlocks. This is implemented via the type system by making all
SILBasicBlock constructors private. Since SILFunction is a friend of
SILBasicBlock, SILFunction can still create a SILBasicBlock without issue.

2. Since all SILBasicBlocks will be created in only a few functions, it becomes
very easy to determine using instruments the amount of memory being allocated
for SILBasicBlocks by simply inverting the call tree in Allocations.

With LTO+PGO, normal inlining can occur if profitable so there shouldn't be
overhead that we care about in shipping compilers.
2016-11-25 01:12:49 -06:00