Commit Graph

85 Commits

Author SHA1 Message Date
Joe Groff
9e98dc1ef0 ConstExpr evaluator: Look through substitution-only convert_function insns 2020-02-24 12:14:21 -08:00
Ravi Kandhadai
52f274a539 [OSLogOptimization] Add support for eliminating dead alloc stacks
using the new InstructionDeleter utility. The elimination logic
exploits the fact that constant_evaluable function calls have
been evaluated and folded, in order to remove such calls that
may possibly take @inout parameters.
2020-01-24 19:36:26 -08:00
Ravi Kandhadai
935686460c [SIL Optimization] Create a new utility InstructionDeleter to delete instructions
and eliminate dead code. This is meant to be a replacement for the utility:
recursivelyDeleteTriviallyDeadInstructions. The new utility performs more aggresive
dead-code elimination for ownership SIL.

This patch also migrates most non-force-delete uses of
recursivelyDeleteTriviallyDeadInstructions to the new utility.
and migrates one force-delete use of recursivelyDeleteTriviallyDeadInstructions
(in IRGenPrepare) to use the new utility.
2019-12-18 13:17:17 -08:00
Ravi Kandhadai
ba7996712a Merge pull request #28350 from ravikandhadai/oslog-exec-test-enable
[OSLogOptimization] Fix a bug in the replaceAllUsesAndFixLifetimes function of the OSLogOptimization pass
2019-11-20 19:38:35 -08:00
Slava Pestov
291364b2f1 Merge pull request #28037 from zoecarver/semantics-def
Semantics attribute definition file
2019-11-20 16:42:29 -05:00
zoecarver
12883d07d9 Merge branch 'master' into semantics-def 2019-11-19 13:02:47 -08:00
Ravi Kandhadai
f319f15655 [OSLogOptimization] Fix a bug in the replaceAllUsesAndFixLifetimes
function of the OSLogOptimization pass that happens when folding a
guaranteed value with a constant (owned) value. The fix inserts the
constant value at the beginning of the borrowed scope of the guaranteed
value rather than at the definition of the guaranteed value.

Update the SIL tests for the new folding pattern and add a test that
catches this bug.

Also, re-enable the OSLogPrototypeExecTest.swift that was disabled
due to this bug.
2019-11-19 11:50:08 -08:00
Michael Gottesman
1a4b362503 [oslog] Fix bug where OSLog was not invalidating any state that it was changing.
This is important both for correctness reasons and for triaging reasons. The
correctness is obvious, but for those unaware there are many triaging utilities
that only verify or print pass output if the pass makes a change as indicated by
invalidating state.
2019-11-18 13:26:50 -08:00
Ravi Kandhadai
633bc7947d [OSLogOptimization] Improve the OSLogOptimization pass so that it can
fold a symbolic closure, which is the representation of a closure literal
in the constant evaluator. This commit improves the function
emitCodeForSymbolicValue so that given a symbolic closure it can emit
SIL code for constructing the closure.

This improvement enables folding the arguments array, which is an array
of closures, by its constant value inferred by constant evaluating the
new OSLog calls.
2019-11-12 18:39:02 -08:00
Ravi Kandhadai
6f086afee2 [SIL Optimization][OSLogOptimization] Improve the OSLogOptimization
pass so that it constant folds array symbolic values inferred by the
constant evaluator when evaluting os log calls.
2019-11-12 18:14:48 -08:00
Ravi Kandhadai
f2ec557619 [OSLogOptimization] Improve the replaceAndFixLifetimes function
of the OSLogOptimization pass. This commit contain two changes:
 - It handles non-OSSA better (but it is meant to be phased out) so
   that array and closure folding can be supported
 - It fixes a bug in the OSSA folding by making sure that when an
   owned value replaces a guaranteed value, the owned value is
   borrowed and the borrow is used in place of the guaranteed value.
2019-11-12 18:14:48 -08:00
Arnold Schwaighofer
8aaa7b4dc1 SILOptimizer: Pipe through TypeExpansionContext 2019-11-11 14:21:52 -08:00
Ravi Kandhadai
882f4d7ba3 [OSLogOptimization] Minor refactoring of the logic for determining
whether a SILValue can be folded and also of the logic for emitting
SIL code for symbolic values.
2019-11-07 16:52:10 -08:00
Ravi Kandhadai
48bc63bb8a [Constant Evaluator] Add support for tracking types with aggregate
symbolic values, which are used to represent constant struct and tuple
instances. Associating those symbolic values with the types of the
aggregate they are representing will allow writing some sanity checks,
and will also make constant folding of the symbolic values easier and
more robust.
2019-11-06 12:47:42 -08:00
zoecarver
2ca448b23d Address review comments
* add namespace
* fix block comment style
* SEMA_ATTR -> SEMANTICS_ATTR
* error when SEMANTICS_ATTR isn't defined
2019-11-02 21:58:26 -07:00
zoecarver
9c1a614efb Fix based on review comments 2019-11-02 13:07:20 -07:00
zoecarver
d4129d8659 Add def file for semantics attributes and use constants instead of cstring literals 2019-11-02 11:36:13 -07:00
Ravi Kandhadai
861c0aaca9 [OSLogOptimization][stdlib/private] Make string interpolation methods
of OSLogMessage constant evaluable and remove @_transparent annotation
from the methods. Also, improve diagnostics in the OSLogOptimization
pass as now it rely on seeing the appendInterpolation/Literal calls.
2019-10-29 19:35:37 -07:00
Ravi Kandhadai
ffd3fef199 [OSLogOptimization] Create a SIL test for OSLogOptimization pass to test folding logic,
add -enable-ownership-stripping-after-serialization flag to OSLog optimization tests,
and update the folding logic and end-of-use discovery logic to handle ownership
and non-ownership SIL.
2019-10-28 15:33:01 -07:00
Michael Gottesman
26a734e58e [sil] Rename ValueOwnershipKind::{Any,None} 2019-10-25 10:28:25 -07:00
Ravi Kandhadai
05e24c0aaf [OSLogOptimization] Improve a comment in the OSLogOptimization pass
and rename a function.
2019-10-11 14:23:44 -07:00
Saleem Abdulrasool
085439781b SILOptimizer: rename cdecl to ctor (NFC)
`cdecl` is a keyword in the non-conforming C++ dialect used on Windows
which expands to `__cdecl`.  Simply rename the variable to avoid the
replacement.  Although it is possible to `#undef cdecl`, renaming makes
it less confusing for non-Windows developers.
2019-10-03 08:44:09 -07:00
Ravi Kandhadai
af5eda5d24 Merge pull request #27419 from ravikandhadai/oslog-backward-dependency-analysis
[SIL Optimization][OSLogOptimization] Improve the logic for discovering the beginning of the string interpolation passed to os log APIs.
2019-10-02 16:45:13 -07:00
Andrew Trick
bddc69c8a6 Organize SILOptimizer/Utils headers. Remove Local.h.
The XXOptUtils.h convention is already established and parallels
the SIL/XXUtils convention.

New:
- InstOptUtils.h
- CFGOptUtils.h
- BasicBlockOptUtils.h
- ValueLifetime.h

Removed:
- Local.h
- Two conflicting CFG.h files

This reorganization is helpful before I introduce more
utilities for block cloning similar to SinkAddressProjections.

Move the control flow utilies out of Local.h, which was an
unreadable, unprincipled mess. Rename it to InstOptUtils.h, and
confine it to small APIs for working with individual instructions.
These are the optimizer's additions to /SIL/InstUtils.h.

Rename CFG.h to CFGOptUtils.h and remove the one in /Analysis. Now
there is only SIL/CFG.h, resolving the naming conflict within the
swift project (this has always been a problem for source tools). Limit
this header to low-level APIs for working with branches and CFG edges.

Add BasicBlockOptUtils.h for block level transforms (it makes me sad
that I can't use BBOptUtils.h, but SIL already has
BasicBlockUtils.h). These are larger APIs for cloning or removing
whole blocks.
2019-10-02 11:34:54 -07:00
Ravi Kandhadai
b2c1540ca2 [SIL Optimization][OSLogOptimization] Improve the logic for
discovering the beginning of the string interpolation passed
to os log APIs.

The implementation follows the chain of dependencies starting
from an initializer call to OSLogMessage until the first
instruction of interpolation is discovered. This is more
robust towards changes to the SIL generation of string
interpolation literals.
2019-09-28 17:59:06 -07:00
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
Ravi Kandhadai
61fd4b1431 [OSLog][Test] Update the new oslog overlay implementation to use
@_semantics("constant_evaluable") annotation to denote constant
evaluable functions.

Add a test suite that uses the sil-opt pass ConstantEvaluableSubsetChecker.cpp
to check the constant evaluability of function in the OSLog
overlay.
2019-09-18 10:44:48 -07:00
Ravi Kandhadai
7a3c6d58f5 [stdlib][oslog] Create an SPI _globalStringTablePointer that exposes
the builtin.globalStringTablePointer to the new OSLog overlay.

Modify the new OSLog implementation to use this SPI instead of
`withCString` to pass the (compiler-generated) format string to
the C os_log_impl ABI.

Move the OSLogOptimization pass before constant propagation in
the pass pipeline so that the SPI and the builtin it uses can be
folded to a string_literal instruction.

Update OSLogTests to work with the changes in the implementation.
2019-07-03 17:25:37 -07:00
Ravi Kandhadai
4d4609a7d8 [os_log][SIL Optimization] Modify the OSLogOptimization pass to run
on ownership SIL.
2019-06-11 17:24:16 -07:00
Ravi Kandhadai
27eefd7311 [os_log][SIL Optimization] Make new os log APIs @_transparent and
change OSLogOptimization pass so that inlining is not performed.
2019-06-11 15:47:21 -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
Richard Wei
c718126be1 Update OSLogOptimizationc.cpp to fix warning.
Fixes the following warning:
```console
third_party/unsupported_toolchains/swift/src/swift/lib/SILOptimizer/Mandatory/OSLogOptimization.cpp:396:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
```
2019-05-19 20:42:52 -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
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
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