Commit Graph

56 Commits

Author SHA1 Message Date
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
Erik Eckstein
c2776c455b Rename SILBasicBlock::getID() -> getDebugID()
Swift SVN r24321
2015-01-09 19:37:03 +00:00
Erik Eckstein
a2f78d768f Add SILBasicBlock::getID() for dumping the block index in debug output.
Swift SVN r24308
2015-01-09 17:04:29 +00:00
Chris Lattner
f460716430 add a SILBasicBlock::removeWithParent method with the obvious semantics
(following LLVM IR), NFC.


Swift SVN r24298
2015-01-09 05:33:32 +00:00
Michael Gottesman
ab838481dd Move SILBasicBlock::getSingleSuccessor from the middle of the predecessor code into the successor code. Also add a const version of it.
Swift SVN r24164
2015-01-01 14:34:49 +00:00
John McCall
b6eb086af8 Add a rather hacky builtin function for constructing
a materializeForSet callback from a closure.

Swift SVN r23993
2014-12-17 22:23:26 +00:00
Michael Gottesman
a1373cd1b6 Add a helper overload of SILBasicBlock::insertBBArgs that takes an
integer index as a position instead of a bbarg_iterator.

Swift SVN r23585
2014-11-28 20:38:54 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
Michael Gottesman
ed124f6651 [func-sig-opts] Expose the ValueDecl argument of SILArgument's
constructor in SILBasicBlock::createArgument.

By default the argument is nullptr so any place that currently does not
need to pass in the ValueDecl will not need to be updated given the new
behavior.

Swift SVN r22379
2014-09-30 03:08:50 +00:00
Michael Gottesman
225a5ca87b [func-sig-opts] Add the call SILFunction::spliceBody() to splice a function's body onto another function.
I also added code to ilist_traits so we can set the parent function on BB to be the new function.

Swift SVN r21729
2014-09-04 23:34:34 +00:00
Michael Gottesman
0f7053bd01 Remove SILBasicBlock::getBBArgIndex(SILArgument *) in favor of SILArgument::getIndex().
The index is a property of the argument. There is no reason from a modeling
perspective to go through the BB to get it.

Swift SVN r21338
2014-08-21 04:06:19 +00:00
Arnold Schwaighofer
2e83bdf01b Add a convenience function on SILBasicBlock to move it after another Block
Swift SVN r19633
2014-07-07 21:05:22 +00:00
John McCall
cd6fc21900 Allow SILBasicBlocks to be constructed after a specific
block, and do so when splitting a block.

Swift SVN r19076
2014-06-22 05:01:06 +00:00
Nadav Rotem
1b650dcdf6 Add helper functions to SILBlock and SILFunction.
Swift SVN r18858
2014-06-13 06:10:07 +00:00
Mark Lacey
8156008cd8 Add a dead code elimination optimization pass.
In a loop like this:
  var j = 2
  for var i = 0; i < 100; ++i {
    j += 3
  }
it will completely eliminate j.

It does not yet support rewriting conditional branches as unconditional
branches in the cases where only empty blocks are control dependent on
an edge. Once this support is added, it will also completely eliminate
the loop itself.

Swift SVN r18615
2014-05-24 07:02:18 +00:00
Mark Lacey
924e30ea61 Rewrite BB args whose only use is in struct/tuple extract.
If we have BB args that are only used in a struct/tuple extract, and
that are generated in each predecessor with a struct/tuple instruction,
retype the BB arg and replace the argument with what would have been the
extracted value.

This provides more opportunties for jump threading to kick in.

Swift SVN r16509
2014-04-18 07:19:33 +00:00
Michael Gottesman
0bc4f9c936 Call SILFunction destructor when we cleanup functions so that if the function contains a function_ref, the function referenced by the function_ref has its refcount properly decrement.
Otherwise a function_ref which was supposed to be deallocated would keep
functions alive.

rdar://16287331

Swift SVN r16192
2014-04-11 01:44:38 +00:00
Nadav Rotem
5f35d44ecf Remove unused arguments from the block argument list.
Swift SVN r15006
2014-03-13 21:29:56 +00:00
Nadav Rotem
cbd1eac034 Add a helper function.
Swift SVN r13092
2014-01-29 06:12:03 +00:00
Argyrios Kyrtzidis
cc8804d570 Ubreak build, accomodate LLVM API changes.
Swift SVN r12094
2014-01-09 09:47:26 +00:00
Michael Gottesman
f9461acf29 Fix whitespace.
Swift SVN r11955
2014-01-06 21:31:24 +00:00
Michael Gottesman
6570a42c9a Add reverse iterators to SILBasicBlock.
Swift SVN r11952
2014-01-06 21:28:03 +00:00
Mark Lacey
0ec7617a2c Simplify enum and Int1 integer_literal instructions.
In cases like the one below, replace the integer_literal instructions
with the condition branching to the block that the instruction is in.

    cond_br %10, bb1, bb3

  bb1:
    %13 = integer_literal $Builtin.Int1, -1
    br bb2(%13 : $Builtin.Int1)

  bb3:
    %18 = integer_literal $Builtin.Int1, 0
    br bb2(%18 : $Builtin.Int1)

Similarly, for
    switch_enum %0 : $Bool, case #Bool.true!enumelt: bb1
  bb1:
    %1 = enum $Bool, #Bool.true!enumelt

  we'll replace the enum with %0.

Use this functionality from within the CFG simplification pass to
simplify basic block args in an attempt to expose opportunities for
further CFG simplification.

Swift SVN r9968
2013-11-05 19:11:45 +00:00
Chris Lattner
db9cda3d96 introduce a SILBasicBlock::getPreds() range to match getSuccs()
Swift SVN r9851
2013-10-31 20:54:59 +00:00
Chris Lattner
03e7b756d0 teach simplify-cfg to merge blocks connected by an uncond branch, when
the dest has no other predecessors.  This fires 6926 times on the stdlib.


Swift SVN r9794
2013-10-30 16:48:59 +00:00
Stephen Lin
3f5c0dbf0e Update SILArgument::getModule(), SILBasicBlock::getModule() and SILInstruction::getModule() signatures to match SILFunction::getModule(), for consistency; standardize usage of SILFunction::getParent() to SILFunction::getModule().
Swift SVN r8932
2013-10-04 21:12:20 +00:00
Anna Zaks
5b71c8dcc5 [SIL] Propagate basic block arguments.
Propagate/remove basic block input values when all predecessors supply
the same arguments. Another optimization needed to fold 'true'.

TODO: I need to figure out additional surcumstances in which to to trigger this
optimization and if we need to rerun CCP after this. (For example, we need to
rerun this after constant folding the terminator in order to fold 'true'.)

Swift SVN r8518
2013-09-20 21:53:28 +00:00
Anna Zaks
4d7de376bb [SIL] Refactor splitBasicBlock() into splitBasicBlock and splitBasicBlockAndBranch
This API is more explicit and avoids relying on passing around empty SILLocation.
(No functional change.)

Swift SVN r7988
2013-09-06 17:46:12 +00:00
Chris Lattner
a864b8ea00 enhance the union retain/release implementations to split the block when
inserting a diamond into the middle of an existing block.  This fixes a
problem that manifests in memory promotion when lowering an assign.


Swift SVN r7917
2013-09-04 22:02:50 +00:00
Michael Gottesman
c86a54a438 Renamed SILBasicBlock::getInsts() => SILBasicBlock::getInstList() as discussed on the list.
Swift SVN r7776
2013-08-30 03:40:37 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Stephen Lin
4ae68cd72f Completion of MandatoryInlining pass: recursive inlining, multiple basic blocks, and diagnosis of circular inlining.
Swift SVN r7242
2013-08-14 22:30:21 +00:00
Anna Zaks
e5c3a7ea80 [SIL] Make sure SILBasicBlock destructor gets called.
This also ensures that the instructions indie the basic block
get destructed.

Swift SVN r6667
2013-07-27 00:25:03 +00:00
Anna Zaks
098f197cb8 [SIL] Add convenience SILBasicBlock successor iterators.
Swift SVN r6665
2013-07-27 00:25:02 +00:00
Chris Lattner
c7373c563b add regular convenience methods to SIL IR objects for getting parent containers.
Add a getOperand(n) method to SILInstruction.


Swift SVN r6425
2013-07-21 06:12:29 +00:00