Commit Graph

871 Commits

Author SHA1 Message Date
Ravi Kandhadai
22861ec0fd [Constant Evaluator] Pass assert configuartion option to the
evaluator to precisely evaluate Builtin.assert_configuration.

Unify UnknownReason::Trap and UnknownReason::AssertionFailure error
values in the constant evaluator, now that we have 'condfail_message'
SIL instruction, which provides an error message for the traps.
2019-09-18 17:35:46 -07:00
swift-ci
1fdda8eaa8 Merge remote-tracking branch 'origin/master' into master-next 2019-09-17 19:09:48 -07:00
swift-ci
1fe9aa60dd Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-17 19:03:56 -07:00
Ravi Kandhadai
032442da93 [Constant Evaluator] Add a new sil-opt pass to check constant evaluability
of Swift code snippets. Add a new test: constant_evaluable_subset_test.swift
that tests Swift code snippets that are expected to be constant evaluable and
those that are not.
2019-09-16 18:49:19 -07:00
Ravi Kandhadai
b59cc7ad6a [Constant Evaluator] Add support to the constant evaluator for:
1. builtin "int_expect", which makes the evaluator work on more
integer operations such as left/right shift (with traps) and
integer conversions.

2. builtin "_assertConfiguration", which enables the evaluator
to work with debug stdlib.

3. builtin "ptrtoint", which enables the evaluator to track
StaticString

4. _assertionFailure API, which enables the evaluator to report
stdlib assertion failures encountered during constant evaluation.

Also, enable attaching auxiliary data with the enum "UnknownReason"
and use it to improve diagnostics for UnknownSymbolicValues,
which represent failures during constant evaluation.
2019-09-16 15:12:22 -07:00
swift-ci
0ef2397dab Merge remote-tracking branch 'origin/master' into master-next 2019-09-12 07:50:20 -07:00
swift-ci
bf2a8dc767 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-12 07:44:17 -07:00
Erik Eckstein
8cdeb45284 StackNesting: fix a corner case crash related to unreachable blocks
When deallocs are inserted at block boundaries, it's necessary to recompute the data flow.

rdar://problem/55249524
2019-09-12 13:08:31 +02:00
Mike Ash
f5e7ab866c Merge branch 'master' into master-next 2019-09-09 12:11:25 -04:00
swift-ci
aa7fa85a37 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-06 21:43:32 -07:00
Nate Chandler
211e6562d8 [SILOptimizer] Added MandatoryCombiner.
Minimal commit to get the mandatory combiner rolling.  The intent of the
mandatory combiner is to do basic transformations after the diagnostics
passes have run at the beginning of both the Onone and the performance
pipelines.  For now, it simply visits reachable instructions and does
no work.  In a subsequent commit, apply instructions will be processed
and replaced if they are calls to partial applies defined in the same
function.  At that point an attempt will be made to eliminate the
partial apply altogether.

For now, the pass does no work and is not part of any pipeline.
2019-09-06 15:44:57 -07:00
swift-ci
8b82982f5f Merge remote-tracking branch 'origin/master' into master-next 2019-09-06 11:29:41 -07:00
swift-ci
b9d1078bf6 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-06 11:23:41 -07:00
Nate Chandler
d2270b9e85 [SIL] Updated instruction worklist.
- Replaced usage of raw map and vector with the type that wraps the
  combination (BlotSetVector); that provided a significant deduplication
  since a sizeable portion of the worklist's implementation was in
  vector and map management now provided by the BlotSetVector.
- Templated over the type of map and vector used by the blot set vector.
- Added SmallSILInstructionWorklist where the map and vector are
  specified to be SmallDenseMap and SmallVector respectively.
- Replaced usages of bare ValueBase with usages of SILValue.
- Renamed zap to resetChecked.

Added a bit of functionality to BlotSetVector, specifically to support
SILInstructionWorklist:

- Made insert return not just the index that the potentially-inserted
  item is at on return but additionally whether an insertion occurred,
  matching the behavior of llvm::DenseMap::insert.
- Added a method to reserve capacity in the backing vector and map:
  BlotSetVector::reserve.
- Added a method to free extra storage used by the backing vector and
  map: BlotSetVector::clear.
- Modified SmallBlotSetVector's template parameters so that only a value
  and size can be specified--that type will always use SmallVector and
  SmallDenseMap for its superclass' VectorT and MapT template
  parameters.
- Updated variable names.
2019-09-06 09:10:26 -07:00
swift-ci
90c4af8130 Merge remote-tracking branch 'origin/master' into master-next 2019-08-30 03:49:39 -07:00
swift-ci
a073fd7621 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-30 03:43:39 -07:00
eeckstein
fd86e850b7 Revert "[SILOptimizer] Added MandatoryCombiner." 2019-08-30 11:45:25 +02:00
swift-ci
1f5005ebf7 Merge remote-tracking branch 'origin/master' into master-next 2019-08-29 15:10:25 -07:00
swift-ci
a3dfad6a2b Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-29 15:04:23 -07:00
Nate Chandler
bed890c6f2 [SILOptimizer] Added MandatoryCombiner.
Minimal commit to get the mandatory combiner rolling.  At the moment,
the mandatory combiner only processes partial apply instructions,
attempting both to replace their applies with applies of their
underlying function refs and also to eliminate them altogether.  That
processing is only done if all the arguments to the apply and to the
partial apply are trivial.

For now, the pass is not part of any pipeline.
2019-08-29 13:24:43 -07:00
swift-ci
abe7c8f49b Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-28 11:04:30 -07:00
swift-ci
5a327571aa Merge remote-tracking branch 'origin/master' into master-next 2019-08-28 10:51:07 -07:00
Erik Eckstein
0e08976600 SILOptimizer: a new optimization to hoist destroys of memory locations
DestroyHoisting moves destroys of memory locations up the control flow as far as possible.
Beside destroy_addr, also "store [assign]" is considered a destroy, because is is equivalent to an destroy_addr + a "store [init]".
The main purpose of this optimization is to minimize copy-on-write operations for arrays, etc. Especially if such COW containers  are used as enum payloads and modified in-place. E.g.

switch e {
  case .A(var arr):
    arr.append(x)
    self = .A(arr)
...

In such a case DestroyHoisting can move the destroy of the self-assignment up before the switch and thus let the array buffer only be single-referenced at the time of the append.

When we have ownership SIL throughout the pass pipeline this optimization will replace the current destroy hoisting optimization in CopyForwarding.
For now, this optimization only runs in the mandatory pipeline (but not for -Onone) where we already have ownership SIL.

SR-10605
rdar://problem/50463362
2019-08-28 15:40:05 +02:00
Arnold Schwaighofer
20efacf2d6 Merge remote-tracking branch 'upstream/master' into master-next 2019-08-26 13:30:41 -07:00
swift-ci
abb9f9b8ab Merge remote-tracking branch 'origin/master' into master-rebranch 2019-08-26 11:05:16 -07:00
Doug Gregor
c8ac000fbb Record specialized signature in (SIL)SpecializeAttr.
Rather than storing the set of input requirements in a
(SIL)SpecializeAttr, store the specialized generic signature. This
prevents clients from having to rebuild the same specialized generic
signature on every use.
2019-08-26 09:54:56 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
Pavel Yaskevich
3d01a3d723 Merge remote-tracking branch 'origin/master' into master-next 2019-08-02 09:57:06 -07:00
Andrew Trick
9627a05e00 Document EscapeAnalysis.
Describe the algorithm in the file-level doc comment. The basic
algorithm in the referenced paper is similar, but the most
interesting/important information is how it is adapted to SIL.
2019-07-30 22:47:11 -07:00
swift-ci
41a15ca578 Merge remote-tracking branch 'origin/master' into master-next 2019-07-19 17:50:28 -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
swift-ci
1373edaba2 Merge remote-tracking branch 'origin/master' into master-next 2019-07-08 10:30:18 -07:00
Andrew Trick
cdae12cca6 ARCAnalysis: fix canNeverUseObject to correctly handle builtins.
This analysis helper was inverting the result for builtins. Builtins
such as "copyMemory" were treated as never using a value.

This manifested in a crash in TestFoundation. NSDictionary's
initializer released the incoming array before copying it. This
crashed later during dictionary destruction.

The crash was hidden by a secondary bug in mayHaveSymmetricInterference
that effectively ignored the result from canNeverUseValue.

Rename the helper to canUseObject, invert the result for builtins, and
fix mayHaveSymmetricInterference to respect the result of
canUseObject.

Note that instructions that cannot access a referenced object
obviously cannot not "interfere" with a release.

Fixing these bugs now allows ARC optimization around dealloc_stack and
other operations that don't care about the reference count.
2019-07-07 22:25:18 -07:00
swift-ci
e2d86960c1 Merge remote-tracking branch 'origin/master' into master-next 2019-06-20 17:29:51 -07:00
Saleem Abdulrasool
38995f5d80 Merge pull request #25070 from moatom/fix-include-guard
Fix include guards
2019-06-20 17:26:08 -07:00
swift-ci
c167e18eb6 Merge remote-tracking branch 'origin/master' into master-next 2019-06-12 11:29:27 -07:00
Michael Gottesman
6575a92d07 [cfg] Make the docs for splitBasicBlockAndBranch clearer.
I found myself worrying about the return type, so this just makes the semantics
of the return type explicit.
2019-06-12 10:23:19 -07:00
moatom
2e95a0d265 Fix include guards 2019-06-02 12:10:43 +09:00
Gwen Mittertreiner
dff6b6e258 Removed uses of PointerUnion3
PointerUnion was generalized to be variadic. Replaced uses of
PointerUnion3 with PointerUnion

See also: git-svn-id:
https://llvm.org/svn/llvm-project/llvm/trunk@360962
91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-20 16:02:41 -07:00
Ravi Kandhadai
9be4fef53a [SIL Optimization] Add a mandatory optimization pass for optimizing
the new os log APIs based on string interpolation.
2019-05-14 18:08:59 -07:00
swift-ci
7ef557e7c8 Merge pull request #24780 from ravikandhadai/constexpr-refactoring 2019-05-14 16:34:48 -07:00
ravikandhadai
f563212f03 Revert "[SIL Optimization] Add a mandatory pass for optimizing the new os log APIs based on string interpolation." 2019-05-14 15:11:05 -07:00
Ravi Kandhadai
8b217afcaf [Const Evaluator] Fix a minor bug in the copy constructor deletion of
`ConstExprStepEvaluator`.
2019-05-14 12:09:57 -07:00
Ravi Kandhadai
b7b46622aa [SIL Optimization] Add a mandatory optimization pass for optimizing
the new os log APIs based on string interpolation.
2019-05-13 19:40:39 -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
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
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