Commit Graph

315 Commits

Author SHA1 Message Date
Roman Levenstein
bf2fdb6764 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 issue reported by build bots is fixed now.

rdar://23303031
2015-11-18 18:14:29 -08:00
Ted Kremenek
8b6d9e9edb Revert "Reduce memory footprint of the Swift compiler"
This reverts commit d58f9486b1.
2015-11-17 21:22:40 -08:00
Roman Levenstein
d58f9486b1 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.

rdar://23303031
2015-11-17 17:26:35 -08:00
Erik Eckstein
7f2522b92e Use getCalleeFunction in some places to simplify code. NFC 2015-11-15 18:29:54 -08:00
Michael Gottesman
9fb54bf4bf Fix for upstream ilist changes. 2015-11-11 16:07:41 -08:00
Mark Lacey
1394af3261 Add TryApplyInst to SILInstruction::mayRelease(). 2015-11-07 13:23:56 -08:00
Mark Lacey
dae482e173 Add SILInstruction::mayRelease().
Refines the results of getReleasingBehavior() by checking the
consumption kind of UnconditionalCheckedCastAddrInst and
CheckedCastAddrBranchInst, as well as whether a CopyAddrInst is an
initialization.
2015-11-05 20:23:49 -08:00
Mark Lacey
5eb64493e4 Add the notion of releasing instructions to SILNodes.def.
This will be used in call graph construction so that we can model calls
to deinits that are potentially called as a result of executing
instructions that can end up releasing memory.
2015-11-04 14:05:09 -08:00
Erik Eckstein
ee988e21cb SIL: Add stack attributes to alloc_ref and dealloc_ref.
For details see docs/SIL.rst.
This is needed for the stack promotion optimization.



Swift SVN r32908
2015-10-27 15:29:20 +00:00
Slava Pestov
7cc59e01d7 SIL: Add DeallocPartialRefInst
This instruction destroys instance variables in a partially-initialized
object, then frees it.

Swift SVN r32661
2015-10-13 19:56:20 +00:00
Slava Pestov
090d723763 SIL: Remove null_class instruction
Swift SVN r32605
2015-10-11 02:11:22 +00:00
Andrew Trick
c20370a664 Remove the last remnants of unchecked_ref_bit_cast
Swift SVN r32598
2015-10-10 05:42:57 +00:00
Nadav Rotem
27a5c7d218 Mark Alloc instructions of the same types as identical.
This change is used (and tested) by an upcoming commit.

Swift SVN r32502
2015-10-07 22:21:45 +00:00
Mark Lacey
230944cc32 Revert deletion of comment.
Inadvertantly removed this in r32347 while shuffling code around.

Swift SVN r32350
2015-09-30 21:36:49 +00:00
Mark Lacey
27a3eb1790 Implement SILInstruction::moveBefore and moveAfter in terms of remove/insert.
Swift SVN r32347
2015-09-30 20:28:34 +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
Adrian Prantl
b50b0c39ac Add an assertion that an inline scope is never thrown away.
Swift SVN r32261
2015-09-26 21:46:28 +00:00
Erik Eckstein
2e1410b8ef Add an << operator to pretty-print SILInstruction::MemoryBehavior.
Swift SVN r31947
2015-09-14 23:33:39 +00:00
Xin Tong
d9796fa786 implement witness_method support in CSE
Swift SVN r31542
2015-08-27 20:19:04 +00:00
Erik Eckstein
3a750fb3c9 Handle strong_retain_unowned in instruction identity comparison.
This allows SILCodeMotion to move strong_retain_unowned instructions.




Swift SVN r29909
2015-07-03 10:26:10 +00:00
Andrew Trick
7565a65235 Introduce unchecked_bitwise_cast SIL instruction.
We need a SIL level unsafe cast that supports arbitrary usage of
UnsafePointer, generalizes Builtin.reinterpretCast, and has the same
semantics on generic vs. nongeneric code. In other words, we need to
be able to promote the cast of an address type to the cast of an
object type without changing semantics, and that cast needs to support
types that are not layout identical.

This patch introduces an unchecked_bitwise_cast instruction for that
purpose. It is different from unsafe_addr_cast, which has been our
fall-back "unknown" cast in the past. With unchecked_bitwise_cast we
cannot assume layout or RC identity. The cast implies a store and
reload of the value to obtain the low order bytes. I know that
bit_cast is just an abbreviation for bitwise_cast, but we use
"bitcast" throught to imply copying a same sized value. No one could
come up with a better name for copying an objects low bytes via:

  @addr = alloca $wideTy
    store @addr, $wideTy
      load  @addr, $narrowTy

Followup patches will optimize unchecked_bitwise_cast into more
semantically useful unchecked casts when enough type information is
present. This way, the optimizer will rarely need to be taught about
the bitwise case.

Swift SVN r29510
2015-06-19 16:29:35 +00:00
Joe Groff
821b0f488e SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29490
2015-06-18 15:47:22 +00:00
Mark Lacey
f56ca1ed68 Revert "SIL: Add a project_box insn to project the address of the value from a box."
This reverts commit r29475 because it conflicts with reverting r29474,
and it looks like that commit is breaking the build of the SpriteKit
overlay.

Swift SVN r29481
2015-06-18 06:27:52 +00:00
Joe Groff
15c29e5d1f SIL: Add a project_box insn to project the address of the value from a box.
Still no implementation yet; we'll need to renovate how boxes work a bit to make them projectable (and renovate SILGen to generate typed boxes for the insn to be useful).

Swift SVN r29475
2015-06-18 04:07:23 +00:00
Erik Eckstein
79967e6f07 Add the possibility to compare SIL instructions with a custom operand compare function.
Swift SVN r29355
2015-06-09 09:20:47 +00:00
Adrian Prantl
1daaf310fb Revert "Reverting commits 29181-29187 to investigate buildbot breakage."
This reverts commit 29189.

Swift SVN r29191
2015-05-31 17:38:32 +00:00
Adrian Prantl
b994bde5b5 Reverting commits 29181-29187 to investigate buildbot breakage.
Swift SVN r29190
2015-05-31 06:13:03 +00:00
Adrian Prantl
ff87787b6d SILCloner: Drop all debug intrinsics without a valid debug scope.
If they describe function arguments there is no way to determine which
function they belong to.

rdar://problem/21109015

Swift SVN r29182
2015-05-31 05:39:29 +00:00
Roman Levenstein
a90887d4b3 [sil-cse] Fix a small bug when doing CSE for objc_protocol instructions.
objc_protocol instruction should be identical to itself.

rdar://20901755

Swift SVN r28431
2015-05-11 18:51:24 +00:00
Nadav Rotem
9eddbf670c CSE static class_method instructions.
Swift SVN r27539
2015-04-21 23:21:16 +00:00
Chris Lattner
42b4a966b0 Introduce a new null_class SIL instruction for forming a null pointer
reference to something of class type.  This is required to model
RebindSelfInConstructorExpr correctly to DI, since in the class case, 
self.init and super.init *take* a value out of class box so that it 
can pass the +1 value without performing an extra retain.  Nothing
else in the compiler uninitializes a DI-controlled memory object
like this, so nothing else needs this.  DI really doesn't like something
going from initialized to uninitialized.

Yes, I feel super-gross about this and am really unhappy about it.  I
may end up reverting this if I can find an alternate solution to this
problem.



Swift SVN r27525
2015-04-21 05:56:55 +00:00
Michael Gottesman
07d5537bf9 Add SILInstruction::moveAfter(SILInstruction *).
I am going to use this in a subsequent SILCodeMotion change.

Swift SVN r26669
2015-03-28 02:47:05 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Erik Eckstein
b0f55d701d Enable bridge_object_to_word instruction for CSE.
Swift SVN r26488
2015-03-24 15:45:56 +00:00
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +00:00
Arnold Schwaighofer
951dc2875a Nuke isSideEffectFree
We can now compute the same result with Inst.mayHaveSideEffects(). NFC.

Swift SVN r25742
2015-03-04 05:03:44 +00:00
Arnold Schwaighofer
cf090c2795 Handle memory behavior of BuiltinInst and FunctionRefInst in SILInstruction
Extend SILInstruction::getMemoryBehavior to check BuiltinInfo, llvm::Attribute,
and EffectsKind.

Swift SVN r25696
2015-03-03 00:45:55 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Mark Lacey
fa49f01edf Support CSE of thin_function_to_pointer/pointer_to_thin_function.
Fixes <rdar://problem/19285001>

Patch by Luqman Aden <luqman_aden@apple.com>.

Swift SVN r24604
2015-01-21 19:36:51 +00:00
Michael Gottesman
6d52d178c1 Move the subclasses of SILInstruction into a new file SILInstructions.cpp.
SILInstruction was getting large (~1700 loc). Now we have two files, one that is
~1000 loc and the other with ~700 loc.

Swift SVN r23937
2014-12-15 14:09:54 +00:00
John McCall
169e4fe319 Add Builtin.UnsafeValueBuffer, which provides opaque
storage for arbitrary values.

A buffer doesn't provide any way to identify the type of
value it stores, and so it cannot be copied, moved, or
destroyed independently; thus it's not available as a
first-class type in Swift, which is why I've labelled
it Unsafe.  But it does allow an efficient means of
opaquely preserving information between two cooperating
functions.  This will be useful for the adjustments I
need to make to materializeForSet to support safe
addressors.

I considered making this a SIL type category instead,
like $@value_buffer T.  This is an attractive idea because
it's generally better-typed.  The disadvantages are that:
- it would need its own address_to_pointer equivalents and
- alloc_stack doesn't know what type will be stored in
  any particular buffer, so there still needs to be
  something opaque.

This representation is a bit gross, but it'll do.

Swift SVN r23903
2014-12-13 01:27:12 +00:00
Erik Eckstein
3b9805b246 Disallow cond_br with identical destinations.
It avoids generation of llvm phi nodes with identical predecessors and differing values.
This change replaces my previous fix of this problem in r23580, where I handled it in IRGen.

There were some discussions about it with the conclusion that it's better to just disallow such cond_br instructions in SIL.
It makes the life easier for some SIL optimizations which can't deal with cond_br with identical destinations.

The original radar is <rdar://problem/18568272> Swift compiler fails with "PHI node has multiple entries for the same basic block with different incoming values!"



Swift SVN r23861
2014-12-11 15:03:49 +00:00
John McCall
3b4e0d307e Intrinsic support for pinning.
Using the intrinsics is obnoxious because I needed them
to return Builtin.NativeObject?, but there's no reasonable
way to safely generate optional types from Builtins.cpp.
Ugh.

Dave and I also decided that there's no need for
swift_tryPin to allow a null object.

Swift SVN r23824
2014-12-10 00:52:48 +00:00
Joe Groff
a247f5d98c SIL parser: Populate conformances of init_existential insns.
And fix some bugs with existential conformances, where we were creating a bogus conformance instead of just using null conformances like other code expects.

Swift SVN r23461
2014-11-20 02:43:23 +00:00
Arnold Schwaighofer
c322b3592d Add a data dependence between opened existential values and method_inst that 'use' them.
Before this patch there was no dependence visible to the optimizer between a
open_existential and the witness_method allowing the optimizer to reorder the
two instruction. The dependence was implicit in the opened archetype but this
is not a concept model by the SIL optimizer.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1 : $@cc(...)
  %4 = apply %3<...>(%2)

This patch changes the SIL representation such that witness_methods on opened
archetypes take the open_existential (or the producer of the opened existential)
as an operand preventing the optimizer from reordering them.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1,
                      %2 : $*@opened("...") FooProto : $@cc(...)
  %4 = apply %3<...>(%2)

rdar://18984526

Swift SVN r23438
2014-11-19 17:22:22 +00:00
Arnold Schwaighofer
e9d650d01c CSE: handle RefToBridgeObjectInst and BridgeObjectToRefInst
rdar://19009279

Swift SVN r23414
2014-11-18 21:46:43 +00:00
Andrew Trick
96688dea2f Silince unused variable warnings.
Swift SVN r23341
2014-11-15 00:37:34 +00:00
Michael Gottesman
fae31cbaa2 [dead-object-elim] Add SILInstruction::mayTrap(), change SILInstruction::mayHaveSideEffects() to call it, and change dead object elimination to call mayHaveSideEffects().
Note that I did not change any actual memory behavior. That will come via a
later cleanup phase. Since this is a correctness fix I wanted to only make
things more conservative.

rdar://18568601

Swift SVN r23311
2014-11-14 00:05:15 +00:00
Michael Gottesman
320abd73fb Remove trailing whitespace and fix up some code to use LLVM style. NFC.
Swift SVN r23310
2014-11-14 00:05:14 +00:00
Erik Eckstein
581a5d02f5 Some bug fixes in the SwitchValueInst and SelectValueInst implementations.
Currently these instructions are not generated, so the bugs didn't cause any problems.



Swift SVN r23301
2014-11-13 09:06:50 +00:00