Commit Graph

65 Commits

Author SHA1 Message Date
Dave Abrahams
96c6c8d519 [stdlib] Fix doc comment formatting
Swift SVN r25009
2015-02-05 19:18:30 +00:00
Dave Abrahams
f7000ce3cb [stdlib] Add unsafeUnwrap(x)
Also the internal version, _unsafeUnwrap, for more-efficiently
unwrapping non-empty optionals.

Swift SVN r25008
2015-02-05 19:18:30 +00:00
Dmitri Hrybenko
ff771d0984 stdlib: use fixed-width Builtin.IntXX types for Swift.Int and UInt
Using the unknown-sized Builtin.Word types complicates producing
compile-time overflow diagnostics.  If we don't know the target Word
size, we don't know if there is an overflow.  But SIL optimizer does not
know the size of Word, this is the point of having the Word type in the
first place.

Also, this opens up more possibilities for optimizations.

rdar://17604532

Swift SVN r24788
2015-01-28 05:22:42 +00:00
Dmitri Hrybenko
877a34e388 stdlib: remove (almost) the assumption that Swift.Int is implemented
in terms of Builtin.Word

Swift SVN r24721
2015-01-25 13:11:37 +00:00
Graham Batty
057c27f009 Disable existential metatype casting on non-objc.
Also fixes getting the size of an instance of a class to
work without it when objective-c interop is turned off.

Swift SVN r24477
2015-01-16 20:27:54 +00:00
Mark Lacey
a8944f4540 Enable mandatory inlining of generic functions with unbound generic types.
This allows us to inline @transparent functions in cases like this:

  @transparent
  func partial<T, U>(x: T, f: (T) -> U) -> U {
    return f(x)
  }

  func applyPartial<U>(x: Int32, f: (Int32) -> U) -> U {
    return partial(x, f)
  }

I had planned on enabling this same behavior in the performance inliner
first in order to be able to test the underlying functionality more
thoroughly, but I hit a blocking issue pretty quickly in type
lowering (rdar://problem/19387372).

Given that @transparent is not currently user-facing, it seems
reasonable to go ahead and enable this now and fix any new issues it
exposes since it should be easy to work around those issues by not using
@transparent.

There were lots of performance differences as a result of this change,
mostly positive. Below I list the 10 largest improvements for each of
-Onone, -O, and -Ounchecked, along with all regressions greater than
10%. I will be opening radars for these.

-Onone
---------------------------------------
ArrayOfPOD                     104.200%
ArrayOfGenericPOD               40.700%
TwoSum                          37.800%
EditDistance                    35.600%
GenericStack                    33.500%
SwiftStructuresStack            29.700%
SwiftStructuresInsertionSort    29.300%
Havlak                          27.200%
NestedLoop                      26.800%
Life                            26.400%

SwiftStructuresTrie            -15.500%

-O
---------------------------------------
TwoSum                          46.200%
GenericStack                    37.900%
SwiftStructuresStack            37.100%
Dictionary                      30.200%
Forest                          27.800%
NSDictionaryImplicitConversion  24.400%
Prims                           23.500%
Dictionary2                     19.600%
DollarFilter                    17.00%
SwiftStructuresQueue            16.600%

NSStringConversion             -22.600%
SwiftStructuresTrie            -25.900%
PopFrontArray                  -44.100%

-Ounchecked
---------------------------------------
SwiftStructuresStack            38.900%
GenericStack                    37.400%
NSDictionaryImplicitConversion  21.200%
TwoSum                          20.500%
Histogram                       16.600%
DollarFilter                    15.900%
DollarFunction                  13.600%
ArrayLiteral                    12.900%
Forest                          12.300%
Prims                           10.300%

ImageProc                      -10.900%
InsertionSort                  -11.200%
StrToInt                       -11.800%
NBody                          -14.900%
SwiftStructuresTrie            -29.900%

Swift SVN r24263
2015-01-08 03:36:08 +00:00
Erik Eckstein
54e1071da0 Add a builtin assumeNonNegative.
It returns the argument and specifies that the value is not negative.
It has only an effect if the argument is a load or call.

The effect of this builtin is that for the load/call argument a positive range metadata is created in llvm ir.

I also added a public function _assumeNonNegative(x: Int) -> Int in the stdlib.
To be on the save side, I prefixed it with an underscore. But maybe it makes sense to make it available for all users.



Swift SVN r23582
2014-11-26 09:53:14 +00:00
Graham Batty
e537c75d0c Revert "Disable existential metatype casting on non-objc."
This reverts commit 3e918838b3708bf2287e7caab437ccf72fe9a3f6.

Swift SVN r23579
2014-11-24 17:42:19 +00:00
Graham Batty
277891d8b5 Disable existential metatype casting on non-objc.
Swift SVN r23575
2014-11-24 17:40:44 +00:00
Joe Groff
b60a30c84b stdlib: Make isUniquelyReferenced shims properly return bool.
rdar://problem/18573806 is fixed.

Swift SVN r23547
2014-11-22 05:36:38 +00:00
Dave Abrahams
de8967e2cd [stdlib] Copious force-inling
Just trying to remove possible overheads in the new Array
implementation.  It doesn't seem to affect performance, though.

Swift SVN r23504
2014-11-21 01:39:54 +00:00
Dave Abrahams
0c1e5265c4 [stdlib] Degenericize some BridgeObject primitives
There's really no reason to make the compiler and optimizer work hard,
here.

Also, make some sanity checks more informative

Swift SVN r23503
2014-11-21 01:39:54 +00:00
Dave Abrahams
1ed31fa31a [stdlib] Fix BridgeStorage!
Fix the test so it actually runs, then fix all the bugs it finds, then
extend the test to cover the no-bits-fast-path functionality.

Swift SVN r23466
2014-11-20 03:41:10 +00:00
Mark Lacey
d344976d3d Remove @inline(__always) on a var decl.
@inline(__always) can only be used on functions and constructors.

Swift SVN r23462
2014-11-20 03:01:43 +00:00
Dave Abrahams
e78ad13b7f [stdlib] Force-inline some bitmask constants
Swift SVN r23454
2014-11-19 22:57:44 +00:00
Dave Abrahams
e581216d28 [stdlib] Fix a comment
Swift SVN r23453
2014-11-19 22:57:44 +00:00
Dave Abrahams
2f29db9bfa [stdlib] Finish incomplete comment
Swift SVN r23432
2014-11-19 06:21:49 +00:00
Dave Abrahams
d4e06bd174 [stdlib] Clean up a sanity check
Swift SVN r23431
2014-11-19 06:21:01 +00:00
Dave Abrahams
68fbea2988 BridgeObject: native object with no spare bits set
Naturally, the fast path for things like Array<Int> has to be that no
masking is required to get at the buffer.  Therefore, the state with no
spare bits set needs to be reserved for native objects.  After the
change, an ObjC non-tagged pointer is stored with all spare bits set, and
native objects are stored with 0..<N bits set, where N is the number of
spare bits.  ObjC tagged pointers are still stored verbatim.

Swift SVN r23430
2014-11-19 06:07:19 +00:00
Dave Abrahams
4111b94d1f [stdlib] _BridgeStorage: use Builtin.BridgeObject
Swift SVN r23348
2014-11-15 01:54:53 +00:00
Graham Batty
04f8efbdf5 Correctly calculate non-objc instance size and rename to reflect.
Renames swift_class_getInstanceSize to
swift_class_getInstancePositiveExtentSize to reflect that it is
the size of the object after the instance address point.

Swift SVN r23333
2014-11-14 22:09:20 +00:00
Michael Gottesman
9a691a55b2 [playgrounds] Implement _swift_isClass(x: Any) -> Bool.
This is acting as a temporary work around until the more general
getTypeKind() is finalized from an API perspective.

The reason that removing this now instead of waiting makes sense is:

1. The previous way playgrounds was performing this check was using the runtime
c++ implementation of swift_isClassOrObjCExistential via @asmname. We
want to move away from the @asmname approach in general since it is
brittle since it leads to loose cupling of dependencies.

2. The @asmname version in playgrounds caused the deserializer to assert since
the c++ version of swift_isClassOrObjCExistential() does not match the signature
of the swift declaration of swift_isClassOrObjCExistential().

This allows us to avoid the aforementioned issues and make forward
progress on re-enabling the playground logger with optimization.

rdar://18841292

Swift SVN r23307
2014-11-13 19:35:59 +00:00
Graham Batty
dc6a776d10 stdlib: Use config directives to work without objective-c.
Swift SVN r23211
2014-11-10 20:06:25 +00:00
Graham Batty
9524ca20b3 stdlib: Move _nilRawPointer to Builtin.swift
Swift SVN r23209
2014-11-10 20:05:26 +00:00
Graham Batty
373414864d Revert "Use config directives to carve out a 'portable' kernel stdlib."
This reverts commit r23202 pending further discussion.

Swift SVN r23205
2014-11-10 18:46:42 +00:00
Graham Batty
dfa260fab1 Use config directives to carve out a 'portable' kernel stdlib.
Swift SVN r23202
2014-11-10 18:03:09 +00:00
Dmitri Hrybenko
8d68624c87 stdlib: fix doc comment syntax and coding style
Swift SVN r22684
2014-10-11 01:33:05 +00:00
Dave Abrahams
5c33278e63 [stdlib] Add ManagedBufferPointer
A revamped version of HeapBuffer that doesn't allow null buffer
references.  Something like this is needed for killing the null array
state.

Swift SVN r22683
2014-10-11 01:10:38 +00:00
Dave Abrahams
e4d8ea49e4 [stdlib] Add a FIXME
Swift SVN r22579
2014-10-07 22:15:09 +00:00
Dave Abrahams
d669b8fd56 [stdlib] Always inline _isClassOrObjCExistential
Swift SVN r22543
2014-10-06 18:40:05 +00:00
Erik Eckstein
a4c7d89671 fix coding style in stdlib: move non-attribute keywords in same line as function declaration
Swift SVN r22275
2014-09-25 08:43:55 +00:00
Dave Abrahams
a00085e6ce [stdlib] Document public non-protocol API thru 'B'
Swift SVN r22186
2014-09-22 21:51:38 +00:00
Dmitri Hrybenko
96d00d70b5 StdlibUnittest: add infrastructure for race tests (see examples)
This will be used to test rdar://18191358

Swift SVN r21836
2014-09-10 11:58:45 +00:00
Dave Abrahams
c16987cc8b [stdlib] Add/use unsafeDowncast
now that <rdar://problem/18184883> is fixed, this factoring can be done

Swift SVN r21647
2014-09-02 17:26:03 +00:00
Dave Abrahams
42a2f263fd [stdlib] Add/use unsafeAddressOf
Turning a class into an UnsafePointer should be available to users, and
both safer and more optimizable than using unsafeBitCast.

Swift SVN r21593
2014-08-29 22:33:13 +00:00
Arnold Schwaighofer
9a7b869faf Revert "Add @effects(readnone) to _swift_isClassOrObjCExistential"
We have not defined whether readnone would potentially allow it to be
speculatively executed which is not desired semantics for
_swift_isClassOrObjCExistential because the metadata might not have been loaded
at the speculative point. Since we don't need the readnone property on this
function after the Builtin.canBeClass change for performance remove it for now.

This reverts commit r21330.

Swift SVN r21422
2014-08-22 21:34:33 +00:00
Arnold Schwaighofer
16e41ada77 Make Builtin.canBeClass return a tri-state
Replace the true/maybe state that Builtin.canBeClass was returning by a
tri-state (yes, no, maybe) allowing the optimizer to use the definite no
answer.  This removes the need of the sizeof check that we had in
isClassOrObjCExistential. It also removes the need to CSE this function since
in most cases we will be able to instantiate canBeClass to yes or no (vs maybe)
at compile time.

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
ClassArrayGetter```````,``988.00````,``337.00```,``644.00``,````````191.7%
DeltaBlue``````````````,``2429.00```,``1927.00``,``460.00``,````````23.9%
Dictionary`````````````,``1374.00```,``1231.00``,``129.00``,````````10.9%
Havlak`````````````````,``1079.00```,``911.00```,``124.00``,````````13.7%
Rectangles`````````````,``924.00````,``541.00```,``379.00``,````````70.1%

radar://16823238

Swift SVN r21331
2014-08-21 00:55:40 +00:00
Arnold Schwaighofer
411ad98fba Add @effects(readnone) to _swift_isClassOrObjCExistential
rdar://17961249

Swift SVN r21330
2014-08-21 00:55:36 +00:00
Arnold Schwaighofer
f1ffbf0e0e Revert "stdlib: Add a _isClassOrObjCExistentialAndSizeofAnyObject function"
This reverts commit r21287.

Discussions ongoing.

Swift SVN r21288
2014-08-19 18:15:24 +00:00
Arnold Schwaighofer
87fe2bf736 stdlib: Add a _isClassOrObjCExistentialAndSizeofAnyObject function
The function _isClassOrObjCExistentialAndSizeofAnyObject encapsulates the
"sizeof(x) == sizeof(AnyObject)" check and the call to
swift_isClassOrObjCExistential. The sizeof(x) check cannot be eliminated at the
SIL level and creates extra control flow such that the call to
swift_isClassOrObjCExistential does not dominate. Encapsulating both checks
results in one function call that does dominate allowing us to CSE calls when we
add the attributes inline(late) and effects(readnone).

benchmark``````````````,``baserun0``,``optrun2``,``delta,``speedup
ClassArrayGetter```````,``977.00````,``571.00```,``409.00``,````````72.0%
DeltaBlue``````````````,``2594.00```,``2086.00``,``311.00``,````````14.9%
Rectangles`````````````,``921.00````,``605.00```,``314.00``,````````52.0%

rdar://17961249

Swift SVN r21287
2014-08-19 18:05:44 +00:00
Dmitri Hrybenko
3a04e0809f stdlib: add a function to squeeze a number in a given range from a hash value
This function mixes the bits in the hash value, which improves Dictionary
performance for keys with bad hashes.

PrecommitBenchmark changes with greater than 7% difference:

``````````Dictionary2`,```1456.00`,```1508.00`,```1502.00`,````624.00`,````607.00`,````592.00`,`864.00`,``145.9%
``````````Dictionary3`,```1379.00`,```1439.00`,```1408.00`,````585.00`,````567.00`,````552.00`,`827.00`,``149.8%
````````````Histogram`,````850.00`,````849.00`,````851.00`,```1053.00`,```1049.00`,```1048.00`,`199.00`,``-19.0%
````````````````Prims`,```1999.00`,```2005.00`,```2018.00`,```1734.00`,```1689.00`,```1701.00`,`310.00`,```18.4%
``````````StrSplitter`,```2365.00`,```2334.00`,```2316.00`,```1979.00`,```1997.00`,```2000.00`,`337.00`,```17.0%
```````````````TwoSum`,```1551.00`,```1568.00`,```1556.00`,```1771.00`,```1741.00`,```1716.00`,`165.00`,```-9.6%

Regressions are in benchmarks that use `Int` as dictionary key: we are just
doing more work than previously (hashing an `Int` was an identity function).

rdar://17962402


Swift SVN r21142
2014-08-12 12:02:26 +00:00
Pete Cooper
16f6c73db9 Use unchecked arithmetic for offsets to HeapBuffer values and elements. If these were able to overflow then we'd have already failed in the initializer of the HeapBuffer
Performance numbers are being noisy, but overall there are some good wins.  The losses are the noisy ones unfortunately.

2Sum           ,        1273.00   ,                1292.00   ,        19.00   ,                -1.5%
Ackermann      ,        1423.00   ,                1663.00   ,        240.00  ,                -14.4%
ArrayLiteral   ,        913.00    ,                869.00    ,        44.00   ,                5.1%
Ary            ,        1278.00   ,                1278.00   ,        0.00    ,                0.0%
Ary2           ,        1667.00   ,                1656.00   ,        11.00   ,                0.7%
Ary3           ,        1418.00   ,                1380.00   ,        38.00   ,                2.8%
DeltaBlue      ,        2480.00   ,                2437.00   ,        43.00   ,                1.8%
Dictionary     ,        606.00    ,                594.00    ,        12.00   ,                2.0%
Dictionary2    ,        879.00    ,                862.00    ,        17.00   ,                2.0%
Dictionary3    ,        878.00    ,                871.00    ,        7.00    ,                0.8%
EditDistance   ,        1427.00   ,                1404.00   ,        23.00   ,                1.6%
Fibonacci      ,        1351.00   ,                1335.00   ,        16.00   ,                1.2%
ForLoops       ,        1978.00   ,                1976.00   ,        2.00    ,                0.1%
Forest         ,        1091.00   ,                1076.00   ,        15.00   ,                1.4%
GlobalClass    ,        1714.00   ,                1619.00   ,        95.00   ,                5.9%
Hash           ,        971.00    ,                915.00    ,        56.00   ,                6.1%
HeapSort       ,        1321.00   ,                1261.00   ,        60.00   ,                4.8%
Histogram      ,        1085.00   ,                1079.00   ,        6.00    ,                0.6%
Life           ,        67.00     ,                63.00     ,        4.00    ,                6.3%
LinkedList     ,        1586.00   ,                1535.00   ,        51.00   ,                3.3%
MatMul         ,        239.00    ,                240.00    ,        1.00    ,                -0.4%
Memset         ,        53.00     ,                53.00     ,        0.00    ,                0.0%
MonteCarloE    ,        1243.00   ,                1242.00   ,        1.00    ,                0.1%
MonteCarloPi   ,        993.00    ,                1010.00   ,        17.00   ,                -1.7%
NBody          ,        44.00     ,                43.00     ,        1.00    ,                2.3%
Phonebook      ,        1416.00   ,                1402.00   ,        14.00   ,                1.0%
PrimeNum       ,        347.00    ,                351.00    ,        4.00    ,                -1.1%
Prims          ,        1556.00   ,                1523.00   ,        33.00   ,                2.2%
QuickSort      ,        103.00    ,                101.00    ,        2.00    ,                2.0%
R17315246      ,        1080.00   ,                1076.00   ,        4.00    ,                0.4%
RC4            ,        26.00     ,                25.00     ,        1.00    ,                4.0%
RIPEMD         ,        798.00    ,                767.00    ,        31.00   ,                4.0%
Rectangles     ,        1008.00   ,                972.00    ,        36.00   ,                3.7%
SmallPT        ,        1004.00   ,                1040.00   ,        36.00   ,                -3.5%
StrToInt       ,        795.00    ,                815.00    ,        20.00   ,                -2.5%
StringBuilder  ,        795.00    ,                858.00    ,        63.00   ,                -7.3%
StringWalk     ,        1233.00   ,                1322.00   ,        89.00   ,                -6.7%
Totals         ,        38274.00  ,                38145.00  ,        129.00  ,                0.3%
Walsh          ,        135.00    ,                140.00    ,        5.00    ,                -3.6%

Swift SVN r20569
2014-07-25 22:49:24 +00:00
Pete Cooper
b68de9d4c0 Update strideof in stdlib to call new strideof_nonzero.
This hides the call to max in the compiler and removes the control flow
associated with max.  The resulting -O3 performance is

2Sum           ,  1303.00   ,  1286.00   ,  17.00     ,        1.3%
Ackermann      ,  4077.00   ,  4498.00   ,  421.00    ,        -9.4%
DeltaBlue      ,  19473.00  ,  17265.00  ,  2208.00   ,        12.8%
Dictionary     ,  882.00    ,  817.00    ,  65.00     ,        8.0%
EditDistance   ,  1467.00   ,  1416.00   ,  51.00     ,        3.6%
ForLoops       ,  1998.00   ,  2014.00   ,  16.00     ,        -0.8%
Forest         ,  1125.00   ,  1055.00   ,  70.00     ,        6.6%
GlobalClass    ,  1633.00   ,  1640.00   ,  7.00      ,        -0.4%
Hash           ,  1634.00   ,  945.00    ,  689.00    ,        72.9%
Histogram      ,  1196.00   ,  1054.00   ,  142.00    ,        13.5%
Life           ,  71.00     ,  64.00     ,  7.00      ,        10.9%
LinkedList     ,  1573.00   ,  1573.00   ,  0.00      ,        0.0%
Memset         ,  5987.00   ,  273.00    ,  5714.00   ,        2093.0%
NBody          ,  208.00    ,  44.00     ,  164.00    ,        372.7%
Phonebook      ,  2193.00   ,  1486.00   ,  707.00    ,        47.6%
PrimeNum       ,  1093.00   ,  393.00    ,  700.00    ,        178.1%
Prims          ,  1710.00   ,  1712.00   ,  2.00      ,        -0.1%
QuickSort      ,  121.00    ,  112.00    ,  9.00      ,        8.0%
R17315246      ,  1109.00   ,  1273.00   ,  164.00    ,        -12.9%
RC4            ,  745.00    ,  63.00     ,  682.00    ,        1082.5%
Rectangles     ,  947.00    ,  1015.00   ,  68.00     ,        -6.7%
SmallPT        ,  1071.00   ,  1088.00   ,  17.00     ,        -1.6%
StringBuilder  ,  928.00    ,  799.00    ,  129.00    ,        16.1%
StringWalk     ,  1221.00   ,  1264.00   ,  43.00     ,        -3.4%
Totals         ,  54980.00  ,  43284.00  ,  11696.00  ,        27.0%
Walsh          ,  1215.00   ,  135.00    ,  1080.00   ,        800.0%

Swift SVN r20509
2014-07-24 18:44:42 +00:00
Pete Cooper
3590f4a896 Alignof can never return 0, so don't max against 1
Swift SVN r20507
2014-07-24 18:44:41 +00:00
Dave Abrahams
d00e888d95 [stdlib] Rename reinterpretCast => unsafeBitCast
Also give unsafeBitCast an explicit type parameter.  So

  let x: T = reinterpretCast(y)

becomes

  let x = unsafeBitCast(y, T.self)

Swift SVN r20487
2014-07-24 13:17:36 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Dmitri Hrybenko
d14f17beef Change 'getLogicValue()' into a property 'boolValue'; change
'getArrayBoundValue()' into a property 'arrayBoundValue'.

rdar://17156123


Swift SVN r20304
2014-07-22 12:08:10 +00:00
Dave Abrahams
3731a0d1d2 [stdlib] Deal with various zero-division scenarios
Primarily, this means becoming resilient to Builtin.strideof(x) == 0.
Pretty much the only way to get pointers and arrays to make sense is to
treat zero-sized elements as having a stride of 1, so we do that in our
wrapper for Builtin.strideof.  Other points include precondition checks
for radixes in number formatting.

Fixes <rdar://problem/17097768>

Swift SVN r20242
2014-07-21 05:21:22 +00:00
Dave Abrahams
cbcf9aba21 s/LogicValueType/BooleanType/
We're moving toward using that protocol for straight-up Bool types

Swift SVN r19884
2014-07-12 18:58:18 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00