Commit Graph

3736 Commits

Author SHA1 Message Date
Andrew Trick
320759227a Canonicalize stores in the CanonicalizeInstruction utility.
This is the complement to load canonicalization. Although store
canonicalization is not required before diagnostics, it should be
defined in the same utility.
2019-05-09 13:00:39 -07:00
eeckstein
6e533361dc Merge pull request #24619 from eeckstein/fix-unreachble-utility
SILOptimizer: replace the recursive CFG walk in the RemoveUnreachable utility with a worklist algorithm.
2019-05-09 09:25:44 -07:00
Arnold Schwaighofer
c3bf40c9d7 Merge pull request #24621 from aschwaighofer/opaque_specializer_fixes
Opaque specializer fixes
2019-05-09 07:59:12 -07:00
Andrew Trick
6b1af3de0e Merge pull request #24458 from atrick/clean-accessed-storage
Remove macros and visitors from AccessedStorage.
2019-05-08 16:23:08 -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
Erik Eckstein
b058869656 SILOptimizer: replace the recursive CFG walk in the RemoveUnreachable utility with a worklist algorithm.
This avoids deep stack nesting for large CFGs. It also makes the code simpler.
2019-05-08 13:55:00 -07:00
nate-chandler
5e7f06d3f1 Merge pull request #24546 from nate-chandler/nate/omit-return-pr-fixes
Address PR comments on return omission.
2019-05-07 16:48:41 -07:00
Nate Chandler
1267f659c6 Address PR comments on return omission. 2019-05-07 14:20:21 -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
52237aaaf7 Avoid else-return in splitAggregateLoad. 2019-05-06 17:23:08 -07:00
Andrew Trick
f151a96644 Add a comment on replaceUsesOfExtract per review feedback. 2019-05-06 17:23:08 -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
Andrew Trick
ca9ae0dda8 Canonicalize nontrivial loads.
This adds support to the load->struct_extract canonicalization for
nontrivial element types which look like:

load [copy]
borrow
struct_extract
...uses...
end_borrow
destroy
2019-05-06 17:23:08 -07:00
ravikandhadai
a282b4513d Merge pull request #24488 from ravikandhadai/inliner-refactoring
[SIL Inlining] Extract out a reusable code snippet in PerformanceInliner into a utility function in SILInliner.
2019-05-06 15:13:23 -07:00
Arnold Schwaighofer
1607fa0044 Fix unused variable warning.
NFC.
2019-05-06 14:11:17 -07:00
Andrew Trick
f395f86039 Canonicalize loads in SILGenCleanup.
Reimplement load instruction canonicalization as part of the
CanonicalizeInstruction utility.
2019-05-06 13:31:35 -07:00
Andrew Trick
301ff8c9f0 Add a SILGenCleanup pass.
The SILGenCleanup pass runs before diagnostics to perform any
canonicalization required by diagnostics.
2019-05-06 09:36:08 -07:00
Andrew Trick
9aa2523393 Add a CanonicalizeInstruction utility.
CanonicalizeInstruction will be a superset of
simplifyInstruction (once all the transforms are fixed for ownership
SIL). Additionally, it will also include simple SSA-based
canonicalization that requires new instruction creation. It may not
perform any optimization that interferes with diagnostics or increases
compile time.

Canonicalization replaces simplifyInstruction in SILCombine so we can
easily factor some existing SILCombine transforms into canonicalization.
2019-05-06 09:36:07 -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
Andrew Trick
5cd187d834 Remove macros and visitors from AccessedStorage.
Cleaning up in preparation for making changes that improve
compile-time issues in AccessEnforcementOpts.

This is a simple but important enum with a handful of cases. The cases
need to be easily referenced from the header. Don't define them in a
separate .def. Remove the visitor biolerplate because it doesn't serve
any purpose.

This enum is meant to be used with covered switches. The enum cases do
not have their own types, so there's no performance reason to use a
Visitor pattern.

It should not be possible to add a case to this enum without carefully
considering the impact on the encoding of this class and the impact on
each and every one of the uses. We always want covered switches at the
use sites.

This is a major improvement in readability and usability both in the
definition of the class and in the one place where a visitor was used.
2019-05-02 18:08:27 -07:00
Arnold Schwaighofer
a5036a97df Fix generic specialization that can result in noreturn apply without unreachable
rdar://50393169
2019-05-02 16:12:21 -07:00
ravikandhadai
d912e3312e Merge pull request #24113 from ravikandhadai/constexpr-skip
[Const evaluator] Add support to "skip" instructions in step-wise evaluation
2019-05-02 15:52:05 -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
aa376a4e66 Merge pull request #24224 from aschwaighofer/specialize_opaque_result_types
Add a pass to specialize opaque type archetypes.
2019-05-02 04:40:54 -07:00
ravikandhadai
26dc0921ed Merge pull request #24410 from ravikandhadai/consteval_inject_enum_addr
[Const Evaluator] Add support for inject_enum_addr, select_enum and select_enum_addr
2019-05-01 16:53:11 -07:00
Ravi Kandhadai
cb9cb31f7a [Const Evaluator] Add support for inject_enum_addr, select_enum
and select_enum_addr instructions to the constant evaluator.
2019-05-01 11:06: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
Ravi Kandhadai
b0e56f70f9 [Const evaluator] Enable stepwise constant evaluator to skip
instructions without evaluating them while conservatively accounting
for the effects of the skipped instructions on the interpreter state.
2019-04-30 15:36:29 -07:00
Ravi Kandhadai
a7b7db7854 [Constant Evaluator] Move "string.append" semantics attribute from
`String.+=` function to `String.append` function, and use a new
semantics attribute for String.+=.

Teach the constant evaluator about `String.Append` instead of `String.+=`.
2019-04-30 14:26:06 -07:00
Erik Eckstein
34931428e1 EscapeAnalysis: handle SILUndef values
fixes a crash

rdar://problem/50279857
2019-04-29 13:37:03 -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
nate-chandler
155a155000 Merge pull request #23251 from nate-chandler/nate/omit-return
Allow return to be omitted from single expression functions.
2019-04-25 08:36:34 -07:00
swift-ci
d24bc38797 Merge pull request #23701 from DougGregor/property-delegates-as-custom-attributes 2019-04-24 22:51:18 -07:00
Nate Chandler
4f269fc6c0 Added diagnostic for dangling expression at end.
If the final expression in a function or closure which is missing a
return has the appropriate type, rather than producing the usual
diagnostic about a missing return, produce a diagnostic with a fixit to
insert a return before thatn final expression.

h/t Nate Cook
2019-04-24 09:59:54 -07:00
ravikandhadai
faa6693eec Merge pull request #24004 from ravikandhadai/constexpr-diagnostics-refactoring
[Const evaluator] Improve diagnostics for unknown symbolic values
2019-04-23 17:10:43 -07:00
Doug Gregor
03f674018b Eliminate a use-after-free in assign_by_delegate lowering.
ASan is magic. Thank you, ASan.
2019-04-23 11:32:28 -07:00
Erik Eckstein
e1674232c7 RawSILInstLowering: lower assign_by_delegate 2019-04-23 11:32:28 -07:00