Commit Graph

2592 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
a793dfb451 Respect resilience when specializing opaque type archetypes 2019-05-01 09:31:07 -07:00
Arnold Schwaighofer
881d9ad2bf Fix assert in type substitution cloner
We might have to replace opaque archetypes to satisfy equality of types
2019-05-01 09:31:07 -07:00
Arnold Schwaighofer
9f83f4b088 Projections should keep the type of the underlying type 2019-05-01 09:31:07 -07:00
Arnold Schwaighofer
fbf09031e4 Add a pass to specialize opaque type archetypes.
Clones functions containing opaque type archetypes replacing the opaque
type by a concrete type.

rdar://46140751
2019-05-01 09:31:07 -07:00
Slava Pestov
16d5716e71 SIL: Use the best resilience expansion when lowering types
This is a large patch; I couldn't split it up further while still
keeping things working. There are four things being changed at
once here:

- Places that call SILType::isAddressOnly()/isLoadable() now call
  the SILFunction overload and not the SILModule one.

- SILFunction's overloads of getTypeLowering() and getLoweredType()
  now pass the function's resilience expansion down, instead of
  hardcoding ResilienceExpansion::Minimal.

- Various other places with '// FIXME: Expansion' now use a better
  resilience expansion.

- A few tests were updated to reflect SILGen's improved code
  generation, and some new tests are added to cover more code paths
  that previously were uncovered and only manifested themselves as
  standard library build failures while I was working on this change.
2019-04-26 22:47:59 -04:00
Slava Pestov
472787bab7 SIL: isNonThrowing parameter of SILBuilder::create{Begin,}Apply() defaults to false
Also remove the overload of createApply() that does not take a SubstitutionMap.
It accomplishes nothing except creating ambiguity.
2019-04-25 22:27:38 -04:00
Erik Eckstein
a402544588 SILOptimizer: support for Dictionary literals generated in the data section.
Actually: generate the array of (key, value) tuples in the data section, which is then passed to Dictionary.init(dictionaryLiteral:)
We already do this for simple arrays, e.g. arrays with trivial element types.
The only change needed for dictionary literals is to support tuple types in the ObjectOutliner.

The effect of this optimization is a significant reduction in code size for dictionary literals - and an increase in data size.
But in most cases there is a considerable net win for code+data size in total.
2019-04-23 09:02:53 -07:00
Michael Gottesman
f7b014b95c [cast-opt] Rename CastOptimizer member vars to match the rest of the CastOptimizer.
Done using Xcode's refactoring engine.
2019-04-12 11:09:29 -07:00
Erik Eckstein
4e9a9cc626 SimplifyCFG: disable some expensive optimizations for huge functions.
Disable constant folding and jump threading for functions with > 10000 blocks.
Those optimizations are not strictly linear with the number of blocks and cause compile time issues if the function is really huge.

SR-10209
rdar://problem/49522869
2019-04-10 10:37:37 -07:00