Commit Graph

90 Commits

Author SHA1 Message Date
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
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
Saleem Abdulrasool
ca539d9694 SIL: remove unnecessary forward declaration
This removes the forward declaration for the class which is unnecessary.  NFC.
2016-08-24 16:17:24 -07:00
Erik Eckstein
f2036fc836 SIL: remove unused function removeFromParent from SILBasicBlock.
This function does not make sense anyway because there is no way to re-insert a removed block into a function again.
2016-04-06 14:55:47 -07:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Michael Gottesman
f3c8c5a774 Create SILBasicBlock::getSuccessorBlocks().
This just runs a transform range on getSuccessor()'s ArrayRef<SILSuccessor> so
one does not need to always call Successor.getBB() when iterating over successor
blocks. Instead the transform range does that call for you.

I also updated some loops to use this new SILBasicBlock method to make sure that
the code is tested out by tests that are already in tree. All these places
should be functionally the same albeit a bit cleaner.
2015-12-15 00:36:56 -06:00
Roman Levenstein
46b58ac699 Re-apply "Reduce memory footprint of the Swift compiler"
Use malloc/free for allocating/freeing SIL instructions instead of using the BumpPtrAllocator. This allows for memory reuse and significantly reduces the memory footprint of the compiler.

For example, a peak memory usage during a compilation of the standard library and StdlibUnitTest is reduced by 25%-30%. The performance of the compiler seems to be not affected by this change, i.e. no slowdown is measured.

The use-after-free issues reported by build bots are fixed now.

rdar://23303031
2015-12-10 08:36:59 -08:00
Roman Levenstein
4d02520424 Send delete notifications when basic block arguments are being erased. 2015-12-04 16:00:02 -08:00
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Michael Gottesman
4f2fb63550 [loop-arc] Fix a typo in LoopRegionFunctionInfo::getRegionForNonLocalSuccessor,
Hubris is my name. = /. I put in a verifier check to make sure that we can
properly look up some value and if we have two blocks related via a non-local
successor chain, the first is a CFG level successor of the second.

Swift SVN r32759
2015-10-19 10:22:32 +00:00
Mark Lacey
a3fd30276e Remove SILBasicBlock::getInstList().
There's no longer a need to directly access the instruction list.

Swift SVN r32349
2015-09-30 21:36:46 +00:00
Mark Lacey
255a01f731 Add SILBasicBlock::spliceAtEnd.
Use it in lieu of directly accessing the instruction list and splicing
it in the same manner.

Swift SVN r32343
2015-09-30 19:12:54 +00:00
Mark Lacey
0c9fb63d60 Add push_front()/push_back() to SILBasicBlock.
Use these in place of getInstList().push_front()/push_back().

Swift SVN r32319
2015-09-29 23:22:18 +00:00
Mark Lacey
9d7dd08ac0 Add back() and front() to SILBasicBlock.
Use them instead of getInstList().back() and getInstList.front().

Swift SVN r32307
2015-09-29 22:02:46 +00:00
Mark Lacey
46b2de075e Add instruction list manipulation functions to SILBasicBlock.
Begin using these functions to encapsulate the instruction list rather
than directly accessing it via getInstList().

Swift SVN r32298
2015-09-29 06:35:49 +00:00
Mark Lacey
9bfc4c431a More conversion to using SILBuilder for instruction creation.
Move the implementation of SILBasicBlock::splitBasicBlockAndBranch into
CFG's util function swift::splitBasicBlockAndBranch since it's the only
user, and update the latter to take a SILBuilder and use it to create
the branch to the split-off block.

Swift SVN r32128
2015-09-21 21:47:05 +00:00
Michael Gottesman
129c2b1aa3 Convert some 'typedefs' to C++11 'using'
Swift SVN r31752
2015-09-08 00:55:38 +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
Michael Gottesman
3c217614b0 [g-arc-opts] Use RCStateTransitions when processing arguments as well.
Swift SVN r26914
2015-04-02 23:24:13 +00:00
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00