Commit Graph

94 Commits

Author SHA1 Message Date
Michael Gottesman
a8c4cc60e8 [gardening] Rename ValueBase::getParentBB() => getParentBlock(). 2016-11-14 00:39:47 -08:00
Bob Wilson
8e3226096e Use pointer_iterator for GraphTraits nodes_iterators.
llvm r279326 changed to consistently dereference iterators to pointers,
so we need to do the same for several of the GraphTraits iterators.
2016-10-15 11:02:20 -07:00
Bob Wilson
d70c85745d Remove NodeType from all GraphTraits.
This is no longer used as of llvm r279475.
2016-10-15 11:02:20 -07:00
Slava Pestov
06750f7f43 SIL Optimizer: Fix bug in EscapeAnalysis::isReachable()
We weren't clearing the worklist flags if returning true here. Oops!

This would manifest as alias analysis returning different results
for the same operands over time, which confused ARC code motion
into dropping release instructions.
2016-09-21 23:25:36 -07:00
practicalswift
acdd10265a [gardening] Fix recently introduced typos. 2016-09-20 13:23:25 +02:00
swift-ci
cfbb150950 Merge pull request #4818 from swiftix/assorted-fixes-3 2016-09-19 15:12:30 -07:00
Erik Eckstein
34a4e6df0a SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-16 11:02:19 -07:00
Roman Levenstein
4bd41929fa [sil-escape-analysis] Teach escape analysis to handle destructors of local objects
Till now, the escape analysis would always pessimistically assume that any strong_release or release_value may result in a destructor call and the object may escape through it. With this change, the escape analysis would determine for local objects whose exact dynamic type is known which destructors would be called and check if local objects may really escape in those destructors.
2016-09-15 22:10:25 -07:00
Roman Levenstein
2736329062 [sil-escape-analysis] Make sure that dealloc_ref and set_deallocating do not have any effect on escaping. 2016-09-15 22:10:25 -07:00
Roman Levenstein
4433ad9c3c [sil-optimizer] Teach analysis passes that some instructions besides apply may result in a function call.
For example, strong_release may call a destructor. This information will be used e.g. by the escape analysis.
As destructors are potential calles now, FunctionOrder analysis will make sure that they will be scheduled for optimizations before their callers.
2016-09-15 22:10:25 -07:00
Dmitri Gribenko
fbb3cf35a5 Revert "New SIL instructions to support tail-allocated arrays in SIL." 2016-09-15 00:25:25 -07:00
Erik Eckstein
b11b60e658 SIL: add new instructions to support tail-allocated arrays in SIL.
The new instructions are: ref_tail_addr, tail_addr and a new attribute [ tail_elems ] for alloc_ref.
For details see docs/SIL.rst

As these new instructions are not generated so far, this is a NFC.
2016-09-14 14:54:18 -07:00
Saleem Abdulrasool
9203283628 SILOptimizer: switch to NodeRef
This adds the typedef and switches uses of NodeType * to NodeRef.  This is in
preparation for the eventual NodeRef-ization of the GraphTraits in LLVM.  NFC.
2016-08-25 13:01:11 -07:00
Erik Eckstein
dda1749f96 EscapeAnalysis: fix handling of return tuples from "array.uninitialized" semantic calls.
fixes rdar://problem/27033210
2016-07-01 11:05:23 +02:00
Erik Eckstein
0ea4fe7b98 EscapeAnalysis: fix a bug in graph merging
This bug can end up in doing wrong stack promotion.
2016-03-29 16:33:47 -07:00
Arnold Schwaighofer
7fb2cceec0 Add a method to _NSContiguousString to facilitate stack promotion
Use it for hashing and comparison.

During String's hashValue and comparison function we create a
_NSContiguousString instance to call Foundation's hash/compare function. This is
expensive because we have allocate and deallocate a short lived object on the
heap (and deallocation for Swift objects is expensive).  Instead help the
optimizer to allocate this object on the stack.

Introduces two functions on the internal _NSContiguousString:
_unsafeWithNotEscapedSelfPointer and _unsafeWithNotEscapedSelfPointerPair that
pass the _NSContiguousString instance as an opaque pointer to their closure
argument. Usage of these functions asserts that the closure will not escape
objects transitively reachable from the opaque pointer.

We then use those functions to call into the runtime to call foundation
functions on the passed strings. The optimizer can promote the strings to the
stack because of the assertion this API makes.

  let lhsStr = _NSContiguousString(self._core) // will be promoted to the stack.
  let rhsStr = _NSContiguousString(rhs._core) // will be promoted to the stack.
  let res = lhsStr._unsafeWithNotEscapedSelfPointerPair(rhsStr) {
    return _stdlib_compareNSStringDeterministicUnicodeCollationPointer($0, $1)
  }

Tested by existing String tests.

We should see some nice performance improvements for string comparison and
dictionary benchmarks.

Here is what I measured at -O on my machine

Name                          Speedup
Dictionary                      2.00x
Dictionary2                     1.45x
Dictionary2OfObjects            1.20x
Dictionary3                     1.50x
Dictionary3OfObjects            1.45x
DictionaryOfObjects             1.40x
SuperChars                      1.60x

rdar://22173647
2016-03-24 05:43:29 -07:00
Arnold Schwaighofer
b5f018a4b1 Mark Array.withUnsafeMutableBuffer as not escaping the array storage.
This is safe because the closure is not allowed to capture the array according
to the documentation of 'withUnsafeMutableBuffer' and the current implementation
makes sure that any such capture would observe an empty array by swapping self
with an empty array.

Users will get "almost guaranteed" stack promotion for small arrays by writing
something like:

  func testStackAllocation(p: Proto) {
    var a = [p, p, p]
    a.withUnsafeMutableBufferPointer {
      let array = $0
      work(array)
    }
  }

It is "almost guaranteed" because we need to statically be able to tell the size
required for the array (no unspecialized generics) and the total buffer size
must not exceed 1K.
2016-03-08 19:37:47 -08:00
Arnold Schwaighofer
fc96c2e53d Teach escape analysis about the semantics of copy_addr instructions
If the copy_addr cannot release the destination then it behaves just like a load
followed by a store.

This allows us to stack promote protocol typed array literals.

  protocol Proto { func at() -> Int }

  func testStackAllocation(p: Proto) {
    var a = [p, p, p]

    for e in a {
      print(e.at())
    }
  }
2016-03-08 15:07:25 -08:00
Michael Gottesman
a5be2fff01 [sil] Use FullApplySite instead of ApplyInst in SILInstruction::getMemoryBehavior().
We were giving special handling to ApplyInst when we were attempting to use
getMemoryBehavior(). This commit changes the special handling to work on all
full apply sites instead of just AI. Additionally, we look through partial
applies and thin to thick functions.

I also added a dumper called BasicInstructionPropertyDumper that just dumps the
results of SILInstruction::get{Memory,Releasing}Behavior() for all instructions
in order to verify this behavior.
2016-02-23 15:00:43 -08:00
Erik Eckstein
3b6a4d8231 Handle array.get_element semantics calls with direct results in SIL optimizations.
Currently the array.get_element calls return the element as indirect result.
The generic specializer will change so that the element can be returned as direct result.
2016-02-22 13:58:10 -08:00
Erik Eckstein
fd566d92bd EscapeAnalysis: fix a problem where a inconsistent connection graph can be generated.
rdar://problem/24686791
2016-02-17 13:27:31 -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
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
Erik Eckstein
e5ad57c77b EscapeAnalysis: less conservative handling of @box types and partial_apply with @box arguments 2016-01-15 12:35:29 -08:00
Erik Eckstein
eff88d8703 EscapeAnalysis: don't crash in case a function_ref is passed to a C-function pointer argument.
Fixes rdar://problem/24183323
2016-01-14 15:20:13 -08:00
Erik Eckstein
5b31b94db4 EscapeAnalysis: handle strong_pin and strong_unpin instructions. 2016-01-13 17:03:10 -08:00
Erik Eckstein
dc84f4151b EscapeAnalysis: add API for checking the escape status of parameters of a function call. 2016-01-13 17:03:10 -08:00
Erik Eckstein
9ad406d5d6 Remove the local_storage type attribute and SIL value category.
They are not used anymore as alloc_stack now returns a single value.
2016-01-06 17:35:27 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
d89b4d45e1 Fix typos in code (non-comment typos). 2015-12-27 13:05:01 +01:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
Erik Eckstein
c5ebaee297 EscapeAnalysis: rename utility function for checking reference semantics and use it in canObjectOrContentEscapeTo
This makes canObjectOrContentEscapeTo less conservative when dealing with addresses of references.
2015-12-23 08:33:44 -08:00
practicalswift
81e7439a9a Fix typos. 2015-12-23 11:16:34 +01:00
Erik Eckstein
fba34ee629 EscapeAnalysis: fix wrong check for refcounted object 2015-12-22 14:52:40 -08:00
Erik Eckstein
dc8dce7739 EscapeAnalysis: some fixes and improvements in the basic graph utility functions. 2015-12-22 12:56:21 -08:00
Erik Eckstein
2ac75840dd EscapeAnalysis: fix bug in alias checking regarding ref_element_addr 2015-12-21 16:44:52 -08:00
Erik Eckstein
9278396769 EscapeAnalysis: fix problem of missing points-to edge in the connection graph.
If a graph had a terminal cycle in a defer-edge path it could end up not having a points-to edge.
2015-12-21 16:44:52 -08:00
Erik Eckstein
ae6fa34645 EscapeAnalysis: some new and changed utility functions to be used by alias analysis and ARC analysis. 2015-12-18 08:02:18 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Andrew Trick
739b0e9c56 Reorganize SILOptimizer directories for better discoverability.
(libraries now)

It has been generally agreed that we need to do this reorg, and now
seems like the perfect time. Some major pass reorganization is in the
works.

This does not have to be the final word on the matter. The consensus
among those working on the code is that it's much better than what we
had and a better starting point for future bike shedding.

Note that the previous organization was designed to allow separate
analysis and optimization libraries. It turns out this is an
artificial distinction and not an important goal.
2015-12-11 15:14:23 -08:00