Commit Graph

2601 Commits

Author SHA1 Message Date
Erik Eckstein
8b11e7ce23 SILOptimizer: handle copy_addr [take] in TempRValueOpt 2019-08-28 12:14:38 +02:00
Nikolai Vazquez
ba0612f2e9 Add Builtin.isConcrete<T>(T.Type) -> Int1
Returns `true` if `T.Type` is known to refer to a concrete type. The
implementation allows for the optimizer to specialize this at -O and
eliminate conditional code.

Includes `Swift._isConcrete<T>(T.Type) -> Bool` wrapper function.
2019-08-27 16:51:09 -07:00
Michael Gottesman
5fc1d1d349 [ownership] Define a new instruction copy_unmanaged_value.
This provides a singular instruction for convert an unmanaged value to a ref,
then strong_retain it. I expanded the definition of UNCHECKED_REF_STORAGE to
include these copy like instructions. This instruction is valid in all SIL.

The reason why I am adding this instruction is that currently when we emit an
access to an unowned (unsafe) ivar, we use an unmanaged_to_ref and a strong
retain. This can look to the optimizer like a strong retain that can potentially
be optimized. By combining the two together into a new instruction, we can avoid
this potential problem since the pattern matching will break.
2019-08-25 21:26:40 -07:00
Arnold Schwaighofer
02683f8254 Merge pull request #26717 from aschwaighofer/fix_specialization_of_thin_to_thick
SpecializeOpaqueArchetypes: Fix specialization of thin_to_thick_function
2019-08-20 07:28:15 -07:00
Erik Eckstein
496ca10302 SimplifyCFG: fix a bug in switch_enum -> select_enum conversion
This bug is > 3 years old. Looks like we didn't hit this SIL code pattern so far.

https://bugs.swift.org/browse/SR-11263
rdar://problem/54312894
2019-08-19 20:32:21 +02:00
Arnold Schwaighofer
058c43e38f SpecializeOpaqueArchetypes: Fix specialization of thin_to_thick_function 2019-08-19 10:07:16 -07:00
swift-ci
bcad9406b7 Merge pull request #26660 from gottesmm/pr-48ba69f9596b774f285285b8aa2f740cb7308563 2019-08-16 12:57:35 -07:00
Michael Gottesman
378c6adbd6 [simplify-cfg] When determining/searching for the end of a switch_enums diamond using single successors, make sure we do not have single block self-loop.
Otherwise, we infinite loop.

rdar://52131975
2019-08-16 11:54:29 -07:00
Erik Eckstein
32c0feb577 SIL: add a [dynamic_lifetime] flag to alloc_stack and alloc_box
This flag is set by DefinitInitialization if the lifetime of the stored value is controlled dynamically.
If the flag is set, it's not (easily) possibly to statically calculate the lifetime of the stored value.
2019-08-13 09:29:05 +02:00
Jordan Rose
844ae38722 Remove some Swift STLExtras that LLVM now provides (#26443)
No functionality change.
2019-07-31 18:34:52 -07:00
Slava Pestov
72c9840025 SILOptimizer: Fix speculative devirtualization of constructor calls
By unintentionally using SILDeclRef::getFuncDecl() we were getting a nullptr back,
and passing it in to ClassDecl::getOverridingDecl(). This started crashing with a
refactoring I'm making. Fix this and add a test.
2019-07-30 15:14:33 -04:00
Michael Gottesman
6da591c9b2 Merge pull request #26233 from gottesmm/pr-eece236dc9ac458c63475f57f405b074b064e388
Revert "Revert "[ownership] Verify functions before we strip ownershi…
2019-07-21 21:48:22 -07:00
Michael Gottesman
819a56e680 [cfg] Extract out erasePhiArgument utility from SimplifyCFG -> CFG.h.
I needed this functionality to fix an edge case bug in closure lifetime fixup.
2019-07-19 16:01:54 -07:00
Michael Gottesman
834aa2da41 Revert "Revert "[ownership] Verify functions before we strip ownership.""
This reverts commit f9c586fae5.
2019-07-18 18:24:21 -07:00
Erik Eckstein
117b1dafe6 Rename the two-parameter Builtin.condfail(c, message) to Builtin.condfail_message(c, message)
This is necessary to also support the old single paramter Builtin.condfail(c)
2019-07-17 17:41:59 +02:00
Erik Eckstein
b40ce6b34f SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-16 14:44:09 +02:00
Erik Eckstein
237a3ef77f SIL: Extend cond_fail by a second operand, which is a static string literal, indicating the failure reason. 2019-07-16 12:31:10 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Erik Eckstein
3fd7eea96c SIL: add a failure message operand to Builtin.condfail
The SIL generation for this builtin also changes: instead of generating the cond_fail instructions upfront, let the optimizer generate it, if the operand is a static string literal.
In worst case, if the second operand is not a static string literal, the Builtin.condfail is lowered at the end of the optimization pipeline with a default message: "unknown program error".
2019-07-12 14:03:13 +02:00
Erik Eckstein
e2d313ef68 SIL: Extend cond_fail by a second operand, which is a static string literal, indicating the failure reason. 2019-07-12 14:03:13 +02:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Ravi Kandhadai
5430aa0b17 [Builtin][SILGen][IRGen] Create a new builtin "globalStringTablePointer":
String -> Builtin.RawPointer that given a string constructed from a
literal, returns the address of the string literal in the global string
table of the compiled binary as a pointer.
2019-07-03 16:47:34 -07:00
Andrew Trick
8116c0b596 ARCCodeMotion: add debug tracing. 2019-07-01 12:00:49 -07:00
Xi Ge
f9c586fae5 Revert "[ownership] Verify functions before we strip ownership."
This reverts commit 7bd15bdb81.
2019-06-24 11:03:41 -07:00
Michael Gottesman
7bd15bdb81 [ownership] Verify functions before we strip ownership.
Today before/after running optimizations, the driver always verifies the entire
SILModule. Sadly since we are stripping ownership in the /middle/ of the
pipeline, we do not get the same benefit for ownership SIL.

With this change, we verify before we strip ownership to ensure that the code is
[ossa] correct /before/ we strip.

This will only run in asserts builds unless -sil-verify-all is passed in.
2019-06-23 22:30:49 -07:00
Arnold Schwaighofer
7e8ce6ce4a Merge pull request #25631 from aschwaighofer/ReplaceOpaqueTypesWithUnderlyingTypes_primary_file_mode
ReplaceOpaqueTypesWithUnderlyingTypes: In primary-file mode there mig…
2019-06-21 08:12:47 -07:00
Michael Gottesman
1980d57cdc Move MarkUninitializedFixup to ./lib/SILOptimizer/Mandatory since it is only used in the mandatory pipeline. 2019-06-20 13:16:07 -07:00
Arnold Schwaighofer
9b3206f415 Add flag that exists on swift-5.1-branch 2019-06-20 12:53:08 -07:00
Andrew Trick
75ff6216af SimplifyCFG: fix a compile time bug from exponential jump threading.
Change the way how to limit jump threading.  Instead of counting the
number of jump threading optimizations on a block, count the number of
copied instructions due to jump threading.

rdar://problem/51416939

Patch by Erik Eckstein!
2019-06-12 15:05:14 -07:00
Arnold Schwaighofer
c187c8ac13 SIL: Replace uses of getReferencedFunction() by getReferencedFunctionOrNull() and getInitialReferencedFunction()
With the advent of dynamic_function_ref the actual callee of such a ref
my vary. Optimizations should not assume to know the content of a
function referenced by dynamic_function_ref. Introduce
getReferencedFunctionOrNull which will return null for such function
refs. And getInitialReferencedFunction to return the referenced
function.
Use as appropriate.

rdar://50959798
2019-05-26 08:58:14 -07:00
Erik Eckstein
5f8a5054c3 DeadObjectElimination: remove dead keypath instructions 2019-05-21 09:44:59 -07:00
Andrew Trick
a9070cf6d4 Add AccessEnforcementOpts fast paths.
1. During identifyAccess, determine if there are either any
identical accesses or an accesses that aren't already marked
no_nested_storage. If there are neither, then skip the subsequent
data flow analysis.

2. In the new StorageSet, indicate whether identical storage was
seen elsewhere in the function. During dataflow, only add an access
to the out-of-scope access set if was marked as having identical
storage with another access.

3. During data flow, don't track in scope conflicts for
instructions already marked [no_nested_conflict].
2019-05-14 15:09:40 -07:00
Andrew Trick
c08e4396ab In AccessEnforcementOpts, skip SCC analysis.
When there is nothing that can be merged, there's no point doing an
extra CFG analysis.
2019-05-14 14:44:21 -07:00
Andrew Trick
cd88cedd86 Slightly reword a comment in AccessEnforcementOpts. 2019-05-14 14:44:20 -07:00
Andrew Trick
c1bda8f090 Replace AccessedStorage projection with an index.
Further simplify AccessedStorage. Shrink it to two words. Remove the
Projection abstraction and streamline the projection logic.
2019-05-14 12:44:46 -07:00
Arnold Schwaighofer
76ea5c041e OpaqueArchetypeSpecializer: Fix casting of types that contain an object type
rdar://50592605
2019-05-08 14:16:00 -07:00
Arnold Schwaighofer
6966f12f9e OpaqueArchetypeSpecializer: InitEnumDataAddr needs to respect type of operand.
rdar://50591831
2019-05-08 14:16:00 -07:00
Arnold Schwaighofer
8cb4456d33 OpaqueArchetypeSpecializer: Fixup switch_enum successor blocks
rdar://50589978
2019-05-08 14:16:00 -07:00
Arnold Schwaighofer
eb3087699a Merge pull request #24533 from aschwaighofer/fix_unused_variable_warning_opaque_specializer
Fix unused variable warning.
2019-05-07 12:14:59 -07:00
Andrew Trick
aa6347c832 Merge pull request #24153 from atrick/fix-let-exclusivity
Add a SILGenCleanup pass and CanonicalizeInstruction utility.
2019-05-06 22:51:19 -07:00
Andrew Trick
ece096d91e Fix eraseFromParentWithdebugInsts to call a callback.
The recursivelyDeleteTriviallyDeadInstructions utility takes a
callBack to be called for every deleted instruction. However, it
wasn't passing this callBack to eraseFromParentWithdebugInsts. The
callback was used to update an iterator in some cases, so not calling
it resulted in iterator invalidation.

Doing this also cleans up the both APIs:
recursivelyDeleteTriviallyDeadInstructions and eraseFromParentWithdebugInsts.
2019-05-06 17:23:08 -07:00
Arnold Schwaighofer
1607fa0044 Fix unused variable warning.
NFC.
2019-05-06 14:11:17 -07:00
Andrew Trick
e400b66897 Cleanup replaceAllUsesAndErase, return an iterator, allow erase handlers.
This will make the forthcoming CanonicalizeInstruction interface more
clear.

This is generally the better approach to utilities that mutate the
instruction stream. It avoids the temptation to assume that only a
single instruction will be deleted or that only instructions before
the current iterator will be deleted. This often happens to work but
eventually fails in the presense of debug and end-of-scope
instructions.

A function returning an iterator has a more clear contract than one
accepting some iterator reference of unknown
providence. Unfortunately, it doesn't work at the lowest level of
utilities, such as recursivelyDeleteTriviallyDeadInstructions, where
we want to handle instruction batches.
2019-05-06 08:36:56 -07:00
Ravi Kandhadai
bed34d65ad [SIL Inlining] Extract out a reusable code snippet in PerformanceInliner
into a utility function in SILInliner.
2019-05-03 15:00:41 -07:00
Arnold Schwaighofer
3089c86f0e Merge pull request #24436 from aschwaighofer/opaque_specializer_fix_cast_nested_types
Opaque archetypes specializer: Fix cast of nested types
2019-05-02 15:45:35 -07:00
Arnold Schwaighofer
52dc2e6d5b Fix circular dependency between SIL and AST libraries 2019-05-02 12:12:50 -07:00
Arnold Schwaighofer
1330d129a8 Opaque archetypes specializer: Fix cast of nested types 2019-05-02 07:20:38 -07:00
Arnold Schwaighofer
f4418ec586 Add copyright notice 2019-05-02 05:21:00 -07:00
Arnold Schwaighofer
cec1a5268e More fixes for opaque types specializer
* Opaque types are abi compatible with their substituted types
* Insert casts in more places
* Respect no optimization attribute
2019-05-01 09:31:07 -07:00
Arnold Schwaighofer
768d1c51a1 Address review feedback 2019-05-01 09:31:07 -07:00