Commit Graph

113 Commits

Author SHA1 Message Date
Roman Levenstein
55ea9ec0e3 [sil-combine] Minor clean-up of casts optimizations. NFC.
Add more checks and logic into emitSuccessfulIndirectUnconditionalCast and emitSuccessfulScalarUnconditionalCast, so that its clients in sil-combine can be simplified by avoiding looking into special cases.

Swift SVN r26885
2015-04-02 19:57:35 +00:00
Roman Levenstein
a7d0eb17ba [sil-combine] casts to/from existentials cannot be further simplified.
This should fix a bug in Adventure reported in rdar://20396204.

Swift SVN r26875
2015-04-02 17:20:23 +00:00
John McCall
6d8fff9c06 Parsing and basic structure of try_apply. Not yet properly
threaded into IRGen; tests to follow when that's done.

I made a preliminary effort to make the inliner do the
right thing with try_apply, but otherwise tried to avoid
touching the optimizer any more than was required by the
removal of ApplyInstBase.

Swift SVN r26747
2015-03-31 02:41:03 +00:00
Roman Levenstein
7011a5f4b4 [generic-specializer] Add support for specializing generic partial_apply instructions.
Use existing machinery of the generic specializer to produce generic specializations of closures referenced by partial_apply instructions. Thanks to the newly introduced ApplyInstBase class, the required changes in the generic specializer are very minimal.

rdar://19290942

Swift SVN r26582
2015-03-26 06:41:30 +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
Mark Lacey
2cec37e73b Use isTransparent() from the referenced function rather than the apply.
When creating a new apply, we were copying the transparent bit from the
old apply, as well as the referenced function from the old apply. We
should just use the transparent bit from that referenced function.

Swift SVN r26384
2015-03-21 02:06:15 +00:00
Roman Levenstein
f3ae8c1f52 Minor clean-up after my recent re-factoring of cast optimizations. NFC.
Swift SVN r26312
2015-03-19 20:03:44 +00:00
Roman Levenstein
848b9ab488 [sil-simplify-cfg] Fold checked_cast_br if a dynamic type of the operand is statically known from alloc_ref
Transforms :

%1 = alloc_ref $B
checked_cast_br [exact] %1 : $B to $B, bb1, bb2

into

br bb1(%1 : $B)

In case when source and destination types do no match, replace by a branch to the failure bb of the checked_cast_br.

Swift SVN r26275
2015-03-18 20:27:44 +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
Roman Levenstein
51ad2d964d Move the logic for type casts optimizations into one place.
This is mostly a re-factoring. It creates a new helper class CastOptimizer which contains all the logic for performing type casts optimizations. This logic is a copy of the current logic from sil-combine and simplify-cfg. Those passes will become clients of this new helper class.

Swift SVN r26122
2015-03-14 02:23:05 +00:00
Arnold Schwaighofer
aa24e126e4 ArraySemantic: Move to its own file in SILAnalysis
I want to use it in ARCAnalysis.

Swift SVN r25924
2015-03-10 15:20:20 +00:00
Arnold Schwaighofer
75710bf9c4 Array property functions were enabled by default
No need to conditionalize code anymore. NFC.

Swift SVN r25894
2015-03-09 22:03:06 +00:00
Arnold Schwaighofer
06f7c40c32 ArraySemanticsCall: Handle @guaranteed parameters
Also improve checking of parameter requirements.

This is needed for our move to +0 self.

radar://20039357

Swift SVN r25798
2015-03-06 03:20:47 +00:00
Arnold Schwaighofer
f7c01f2061 Nuke isReadNone function
We can now compute the same result with Inst.mayReadOrWriteMemory(). NFC.

Swift SVN r25743
2015-03-04 05:03:45 +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
d6cd798de2 stdlib: Add array.props.isNative/needsElementTypeCheck calls
This enables high-level SIL optimizations to speculatively specialize loops into
'fast native swift array' loops vs standard array loops.

This commits adds two semantic calls to Arrays.swift.

   @semantics("array.props.isNative")
   func _getArrayPropertyIsNative() -> Bool

   @semantics("array.props.needsElementTypeCheck")
   func _getArrayPropertyNeedsElementTypeCheck() -> Bool

checkSubscript and getElement get extra arguments to pass in the result of above
function calls. This also allow us to communicate that an array that was made
mutable is always native. The array subscript getter is changed to use the
result of these new calls:

   public subscript(index: Int) -> Element {
     get {
       let isNative = _getArrayPropertyIsNative()
       let needsTypeCheck = _getArrayPropertyNeedsElementTypeCheck()
       _checkSubscript(index, isNative)
       return _getElement(index, isNative, needsTypeCheck)
     }
     mutableAddressWithPinnedNativeOwner {
       _makeMutableAndUniqueOrPinned()
       // When an array was made mutable we know it is a backed by a native
       // array buffer.
       _checkSubscript(index, true)
       return (_getElementAddress(index),
               Builtin.tryPin(Builtin.castToNativeObject(_buffer.owner)))
     }
   }

High-level SIL optimizations will now see a loop like this:

     func f(inout a : A[AClass]) {
         for i in 0..a.count {
           let b = a.props.isNative()
            .. += _getElement(a, i, b)
         }
     }

After proving that ‘a’ does not escape other than to known safe functions, the
optimizer hoists the array property calls out of the loop in a loop versioned
on the array property.

      func f(inout a : A[AClass]) {
        let b2 = a.props.isNative()
        if (!b2) {
          for i in 0..a.count {
             .. += _getElement(a, i, false)
          }
        } else {
          for i in 0..a.count {
            let b = a.props.isNative
            .. += _getElement(a, i, b)
          }
        }
      }

rdar://17955309

Swift SVN r25698
2015-03-03 00:45:59 +00:00
Arnold Schwaighofer
14ddfe1427 Add an API to ArraySemantic call to get the self argument as an operand.
Swift SVN r25619
2015-02-27 22:07:39 +00:00
Arnold Schwaighofer
20b1323da2 ArraySemanticsCall: Don't repeat assertions
SILInstruction::getSelfArgument already performs these.

Swift SVN r25616
2015-02-27 22:07:37 +00:00
Luqman Aden
e1c60464d3 Fold getCmpFunction function into helper method on SILBuilder.
Swift SVN r25416
2015-02-20 04:08:08 +00:00
Luqman Aden
858d8d99df SILCombine: Add cmp_*_T . (zext U->T x, zext U->T y) => cmp_*_T (x, y)
peephole for unsigned/equality comparisons.

Fixes <rdar://problem/19759124>

Swift SVN r25404
2015-02-20 00:39:33 +00:00
Michael Gottesman
669cdc537c Create an entrypoint tryToConcatenateStrings and hide the class StringConcatenationOptimizer in Local.cpp.
In every instance, we were just creating the StringConcatenationOptimizer and
then invoking optimize on it. This is a cleaner solution since the details of
how we perform the string concatenation are hidden in Local.cpp instead of being
in a header.

NFC.

Swift SVN r25341
2015-02-17 01:59:13 +00:00
Arnold Schwaighofer
fdb172e7a3 Only recognize array semantic functions with a self argument when they have a self argument
rdar://19808820

Swift SVN r25242
2015-02-12 17:42:11 +00:00
Michael Gottesman
3b7df81a58 Add in a note. NFC.
Swift SVN r25196
2015-02-11 21:52:28 +00:00
Mark Lacey
03cca73418 Fix naming convention.
Swift SVN r25179
2015-02-11 10:27:19 +00:00
Mark Lacey
c804c50c4d Add a simple utility for determining the lifetime of a value.
This refactors some code out of AllocBoxToStack that computes the
lifetime of a value in the strictess sense, limiting the lifetime to
that value and not anything derived from that value (whether by casting,
projection, etc.).

In the short term this will be used to fix a very rarely hit
optimization in AllocBoxToStack.

Longer term I will replace the other similar code in AllocBoxToStack to
use this instead.

Swift SVN r25176
2015-02-11 10:17:03 +00:00
Michael Gottesman
a5e757c6a2 Improve some comments. NFC.
Swift SVN r25134
2015-02-10 20:25:16 +00:00
Michael Gottesman
436f022867 [local] Add tryDeleteDeadClosures.
This utility attempts to delete dead closures with a set of
post-dominating releases using the infrastructure from
getFinalReleasesForValue.

It currently only will eliminate closures that only have retain, release
uses and a final post-dominating release set.

The reason why we need the final post-dominating release set is so that
we can release any captured variables at the points where we would have
deallocated the release. This is b/c captured variables are passed in at
+1 to partial apply.

Swift SVN r25050
2015-02-06 21:59:52 +00:00
Arnold Schwaighofer
86492b5fa2 ArraySemantics: Use the function type to check for the presence of a self argument
Swift SVN r25027
2015-02-06 01:23:39 +00:00
Arnold Schwaighofer
283a6bee39 Fix users of ArraySemantics::getSelf to correctly handle Array.init
Array.init does not have a self argument (it returns the newly created array
@owned). Passes using the ArraySemantic::getSelf() interface must handle it
specially.

rdar://19724033

Swift SVN r25013
2015-02-05 19:31:23 +00:00
Roman Levenstein
af31899fef Flag -debug-values-propagate-liveness should be always taken into account if provided.
Till now, -debug-values-propagate-liveness was only taken into account if the compiler was built with assertions. This led to some problems with bots, which were testing both assertions-enabled and assertions-disables versions of the compiler. It was agreed that we want this experimental flag to be always taken into account when it is provided on the command-line. The default value of this flag is "disabled".

rdar://19674999

Swift SVN r24977
2015-02-04 21:58:57 +00:00
Arnold Schwaighofer
1e3f67e9c7 global_init functions can have side-effects
We can not remove unused global initializer function calls. They might have
side-effects.

I measured no regressions at -O.

rdar://19464274

Swift SVN r24513
2015-01-19 19:17:14 +00:00
Michael Gottesman
897325b096 Codebase Gardening. NFC.
1. Eliminate unused variable warnings.
2. Change field names to match capitalization of the rest of the field names in the file.
3. Change method names to match rest of the file.
4. Change get,set method for a field to match the field type.

Swift SVN r24501
2015-01-19 00:34:07 +00:00
Adrian Prantl
95eec5a155 Fix Test for: DCE is dropping debug intrinsics, Was: DebugInfo/closure-multivalue test is failing
In order to not completely loose testcoverage while rdar://problem/18709125
is under investiagtion, add a special flag for enabling debug value
liveness.

Patch by Michael Gottesman!

<rdar://problem/19267059>

Swift SVN r24416
2015-01-14 18:37:39 +00:00
Erik Eckstein
31dd17a49f Add array.uninitialized semantics to ArrayCallKind, ArraySemanticsCall and the docs.
For completeness. NFC.



Swift SVN r23955
2014-12-16 13:28:18 +00:00
Arnold Schwaighofer
2f949056d6 SIL utils: Rename array.props.isCocoa to array.props.isNative
The upcoming stdlib patch will also be modified.

NFC

rdar://17955309

Swift SVN r23813
2014-12-09 21:58:16 +00:00
Mark Lacey
9d6e7cddc8 Reapply r23673, which was reverted in r23679.
It had exposed a problem with the MemBehavior on a couple SIL
instructions which resulted in code motion moving a retain across an
instruction that can release (fixed in r23722).

From the original commit message:

    Remove restriction on substituting existentials during mandatory inlining.

    Issues around this have now been resolved, so we should now support
    anything that Sema lets through.

    Fixes rdar://problem/17769717.

Swift SVN r23729
2014-12-05 05:47:42 +00:00
Arnold Schwaighofer
404ce8c599 ArraySemantics: Add support for the upcoming array.props semantic calls
"array.props.isCocoa/needsElementTypeCheck" semantic calls will mark calls that
return array properties: isCocoa and needsElementTypeCheck. We know that said
states can only transfer in certain directions (a native swift array that does
not need an element type check stays in this state) enabling us to version loops
based on the state of said array array properties.

rdar://17955309

Swift SVN r23688
2014-12-04 19:24:39 +00:00
Mark Lacey
2cb14c32fe Revert "Remove restriction on substituting existentials during mandatory inlining."
This reverts commit r23673.

It looks like this broke the DollarChain benchmark so I am backing it
out while I investigate.

Swift SVN r23679
2014-12-04 05:40:49 +00:00
Mark Lacey
f3b82c7bfd Remove restriction on substituting existentials during mandatory inlining.
Issues around this have now been resolved, so we should now support
anything that Sema lets through.

Fixes rdar://problem/17769717.

Swift SVN r23673
2014-12-04 01:12:42 +00:00
Roman Levenstein
8593329a6d Do not forget to drop referenced functions when eliminating function_ref instructions in recursivelyDeleteTriviallyDeadInstructions.
Swift SVN r23655
2014-12-03 21:46:28 +00:00
Roman Levenstein
f8c3dda827 [sil-combine] Move the StringConcatenationOptimizer class into Local.h/.cpp. NFC.
This is done because this class is to be used by sil-combine and constant constant-propagation.

Swift SVN r23654
2014-12-03 21:46:27 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Michael Gottesman
269c372d97 [func-sig-opts] Extract out utility method removeDeadBlocks() from simplifyCFG so I canuse it in FunctionSignatureOpts.
I also extracted out an additional method clearBlockBody() from the body
of removeDeadBlocks() since I need that functionality exposed in
Function Signature Opts.

Swift SVN r22560
2014-10-07 00:53:58 +00:00
Arnold Schwaighofer
c1eefb1dad Reapply "stdlib: Remove dead semantic Array._setElement function
Also remove helper functions."

With fixes.

Swift SVN r22479
2014-10-02 20:26:32 +00:00
Arnold Schwaighofer
2bd116c20b Revert "stdlib: Remove dead semantic Array._setElement function"
This reverts r22468. Because it breaks the build.

Swift SVN r22469
2014-10-02 18:46:24 +00:00
Arnold Schwaighofer
cfd4a0902d stdlib: Remove dead semantic Array._setElement function
Also remove helper functions.

Swift SVN r22468
2014-10-02 18:44:31 +00:00
Arnold Schwaighofer
b6f28bede1 ArraySemantics: Teach array semantics about getting the address of an array element
rdar://18517410

Swift SVN r22439
2014-10-01 21:08:22 +00:00
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Arnold Schwaighofer
813d43415f ArraySemantics: Add wrapper utility for array semantics calls to Local.h
This encapsulates common operations on array semantic calls like identifying
them or hoisting/copying them.

Will be used by follow-up commits. NFC.

Swift SVN r21926
2014-09-12 21:05:22 +00:00