Commit Graph

93 Commits

Author SHA1 Message Date
Michael Gottesman
f35a2a3cf8 [sil-opt] Only notify the pass manager of newly added functions in SILOptFunctionBuilder.
To do so this commit does a few different things:

1. I changed SILOptFunctionBuilder to notify the pass manager's logging
functionality when new functions are added to the module and to notify analyses
as well. NOTE: This on purpose does not put the new function on the pass manager
worklist since we do not want to by mistake introduce a large amount of
re-optimizations. Such a thing should be explicit.

2. I eliminated SILModuleTransform::notifyAddFunction. This just performed the
operations from 1. Now that SILOptFunctionBuilder performs this operation for
us, it is not needed.

3. I changed SILFunctionTransform::notifyAddFunction to just add the function to
the passmanager worklist. It does not need to notify the pass manager's logging
or analyses that a new function was added to the module since
SILOptFunctionBuilder now performs that operation. Given its reduced
functionality, I changed the name to addFunctionToPassManagerWorklist(...). The
name is a little long/verbose, but this is a feature since one should think
before getting the pass manager to rerun transforms on a function. Also, giving
it a longer name calls out the operation in the code visually, giving this
operation more prominance when reading code. NOTE: I did the rename using
Xcode's refactoring functionality!

rdar://42301529
2018-08-06 18:27:24 -07:00
Michael Gottesman
b72304415d [passmanager] Change the optimizer to use SILOptFunctionBuilder.
I am going to add the code in a bit that does the notifications. I tried to pass
down the builder instead of the pass manager. I also tried not to change the
formatting.

rdar://42301529
2018-08-05 21:21:55 -07:00
Michael Gottesman
11b24415c1 [sil-module] Create SILFunctionBuilder and hide creation/erasing functions on SILModule.
This commit does not modify those APIs or their usage. It just:

1. Moves the APIs onto SILFunctionBuilder and makes SILFunctionBuilder a friend
   of SILModule.
2. Hides the APIs on SILModule so all users need to use SILFunctionBuilder to
   create/destroy functions.

I am doing this in order to allow for adding/removing function notifications to
be enforced via the type system in the SILOptimizer. In the process of finishing
off CallerAnalysis for FSO, I discovered that we were not doing this everywhere
we need to. After considering various other options such as:

1. Verifying after all passes that the notifications were sent correctly and
   asserting. Turned out to be expensive.
2. Putting a callback in SILModule. This would add an unnecessary virtual call.

I realized that by using a builder we can:

1. Enforce that users of SILFunctionBuilder can only construct composed function
   builders by making the composed function builder's friends of
   SILFunctionBuilder (notice I did not use the word subclass, I am talking
   about a pure composition).
2. Refactor a huge amount of code in SILOpt/SILGen that involve function
   creation onto a SILGenFunctionBuilder/SILOptFunctionBuilder struct. Many of
   the SILFunction creation code in question are straight up copies of each
   other with small variations. A builder would be a great way to simplify that
   code.
3. Reduce the size of SILModule.cpp by 25% from ~30k -> ~23k making the whole
   file easier to read.

NOTE: In this commit, I do not hide the constructor of SILFunctionBuilder since
I have not created the derived builder structs yet. Once I have created those in
a subsequent commit, I will hide that constructor.

rdar://42301529
2018-07-31 10:04:03 -07:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
Andrew Trick
6ed43afcf8 Fix checks and assertions in -enable-verify-exclusivity mode.
Now that access marker verification is strict and exhaustive, adjust some code
to handle the extra markers and extra checks produced by -enable-verify-exclusivity.
2018-06-29 15:56:02 -07:00
Andrew Trick
025af31572 [NFC] SILGlobalVariable utilities. (#16870)
* SILModule::isVisibleExternally utility for VarDecls.

* Fix the SIL parser so it doesn't drop global variable decls.

This information was getting lost in SIL printing/parsing.
Some passes rely on it. Regardless of whether passes should rely on it,
it is totally unacceptable for the SIL passes to have subtle differences
in behavior depending on the frontend mode. So, if we don't want passes
to rely on global variable decls, that needs to be enforced by the API
independent of how the frontend is invoked or how SIL is serialized.

* Use custom DemangleOptions to lookup global variable identifiers.

* SILGlobalVariable utilities.

Move the utilities that are required for recognizing SILGlobalVariable access
into SILGlobalVariable.[h|cpp].

Structural SIL properties that are assumed by the optimizer, and thus required
for SIL verification, should never be embedded in SILOptimizer passes, or even
in SILOptimizer/Utils. Structural SIL properties need to be defined in
/SIL. They are as much part of the SIL language as the opcode list.

These particular utilities are required for working with SILGlobalVariables, and
will be used by a whole-module access enforcement optimization.

The primary API for recognizing SIL globals is `getVariableOfGlobalInit`. It is
required to find the association between the addressor SILFunction marked
[global_init], and the SILGlobalVariable being addressed.

Other helper APIs expose more details about the addressor's SIL patterns and are
useful for transforming the initializer itself into an optimized form.
2018-06-26 13:26:30 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Michael Gottesman
efca1caa5b Merge pull request #15495 from gottesmm/pr-f8d1bdd4feca6f9af1dd5746b016d839eb34bce1
[globalopt] Cleanup placeInitializers.
2018-03-24 16:47:57 -07:00
swift-ci
f1d2ba305a Merge pull request #15493 from gottesmm/pr-d923c44d599a0725bd7b645cb73ccd9e4b716efb 2018-03-24 15:58:50 -07:00
Michael Gottesman
5b630f2571 [globalopt] Invert a conditional to eliminate a level of indentation from placeInitializers. 2018-03-24 15:31:48 -07:00
Michael Gottesman
33677c8657 [globalopt] Slim down placeInitializers by extracting the subroutine getHoistedApplyForInitializer. 2018-03-24 15:31:48 -07:00
Michael Gottesman
330bfd7319 [globalopt] Remove a commented out assertion.
This assertion is bogus today since global opt can optimize global variables
that are vars that can not be accessed from outside the current module.
2018-03-24 14:51:41 -07:00
swift-ci
7316b98cf4 Merge pull request #15491 from gottesmm/pr-082364da906bdce30bf29fffcfd85e34b019e0bd 2018-03-24 14:42:44 -07:00
Michael Gottesman
a5a96b6673 [gardening] Remove empty anonymous namespace. 2018-03-24 13:43:07 -07:00
Michael Gottesman
8d4f1f3c57 Merge pull request #15483 from gottesmm/pr-90ea31c996d38eec3a1aa9797c1d08c9a53fb356
[globalopt] Eliminate unused field.
2018-03-24 13:40:25 -07:00
Michael Gottesman
ade98f49b6 Merge pull request #15486 from gottesmm/pr-37d155196450aa04e1fd3a5963ebcb06c2fab76b
[globalopt] Eliminate indentation by inverting a condition into an ea…
2018-03-24 13:26:33 -07:00
swift-ci
c7a59c37bf Merge pull request #15487 from gottesmm/pr-aa03a816e41fb717e7cd9953015b077ec25eecc3 2018-03-24 12:19:19 -07:00
swift-ci
8d9dfa47a6 Merge pull request #15485 from gottesmm/pr-524a60964d1eb583711748d34362982011cbe9af 2018-03-24 12:18:09 -07:00
swift-ci
bbcb57661e Merge pull request #15484 from gottesmm/pr-762fbb7b46d42781016643ce31e84d03bbdcf6dc 2018-03-24 12:15:31 -07:00
Michael Gottesman
ddb88c92ac [globalopt] Eliminate unnecessary coercion to SILValue and improve some small other nits. 2018-03-24 11:27:59 -07:00
Michael Gottesman
a99b65c073 [globalopt] Eliminate indentation by inverting a condition into an early exit. 2018-03-24 11:24:48 -07:00
Michael Gottesman
541c2e4b33 [globalopt] Remove a local ToRemove vector that is never appended to.
This didn't trigger any unused variable warnings since we always try to clean up
the contents in the ToRemove vector. Of course since the ToRemove vector is
never actually appended to, nothing ever happens there.

The other aspect of this is whether or not we actually need a ToRemove vector. I
read the code in this section and it is not necessary since the section of
GlobalOpt is only collecting information about the function we are
processing. Later after function iteration is over, we later process the data
that we filled our caches with. So no iterator invalidation can happen.
2018-03-24 11:24:43 -07:00
Michael Gottesman
002326f3b2 [globalopt] Small style fixes. 2018-03-24 11:23:48 -07:00
Michael Gottesman
6e98703391 [globalopt] Eliminate unused field.
Some time ago I believe due to compile time? Not sure, we started to use
ColdBlockInfo in a per function way. So for each function, we instantiate a new
ColdBlockInfo and never use this one. So there is no reason for it to exist...
2018-03-24 11:21:29 -07:00
Michael Gottesman
087769ce5c [globalopt] Use std::reverse instead of trying to reverse an array by hand.
I also changed a dyn_cast to a cast since we assume here that the cast can never
fail.
2018-03-24 11:20:02 -07:00
Michael Gottesman
086171bd8c [globalopt] Clean up doxygen comments in GlobalOpt.cpp.
I need to fix a few things in GlobalOpt to deal with +0 changes I believe. So
while I am here, I am just cleaning up the file a little bit.
2018-03-24 09:37:44 -07:00
Michael Gottesman
51b20a2881 [globalopt][gardening] Standardize "Foo*" => "Foo *"
In most of the file, "Foo *" is used. So this commit just standardizes the rest
of "Foo*" to that.
2018-03-23 13:23:38 -07:00
Erik Eckstein
bf87035a36 GlobalOpt: Move the object outlining from GlobalOpt into a separate pass "ObjectOutliner"
We run GlobalOpt multiple times in the pass pipeline but in some cases object outlining shouldn't be done too early.
Having it done in a separate pass enables to run it independently from GlobalOpt.
2018-01-19 11:32:36 -08:00
eeckstein
b126b62256 Revert "Optimization changes to completely fold OptionSet literals" 2018-01-18 22:05:07 -08:00
Erik Eckstein
1f511ab846 GlobalOpt: Move the object outlining from GlobalOpt into a separate pass "ObjectOutliner"
We run GlobalOpt multiple times in the pass pipeline but in some cases object outlining shouldn't be done too early.
Having it done in a separate pass enables to run it independently from GlobalOpt.
2018-01-18 18:27:17 -08:00
Slava Pestov
d5723cff59 SILOptimizer: Use PublicNonABI linkage for global getters in GlobalOpt
Previously we were creating private [serialized] functions here, which
do not deserialize properly. This was only exposed by making default
argument generators PublicNonABI also.
2018-01-14 22:59:40 -08:00
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Kuba Mracek
0b7bb605cb Don't hardcode the function representation of builtin "once". Make emitLazyGlobalInitializer retrieve the convention from getBuiltinValueDecl. 2018-01-03 10:30:24 -08:00
Michael Gottesman
5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Erik Eckstein
2d95f4993a GlobalOpt/IRGen: Instead of not converting an array of empty elements to a statically initialized array, handle this special case in IRGen. 2017-10-31 17:14:51 -07:00
Erik Eckstein
4a485f54fc GlobalOpt: add assertion for resilient classes 2017-10-27 15:36:36 -07:00
Slava Pestov
a07e991093 SILOptimizer: Fix string switch optimization with resilient stdlib
Progress on <rdar://problem/34794790>, but since the build started failing
some other things broke.
2017-10-26 23:58:50 -07:00
Davide Italiano
5ece6d46e4 [GlobalOpt] Fix style/indentation and add a comment. NFCI. 2017-10-26 16:18:11 -07:00
Davide Italiano
423eb798da [GlobalOpt] Defer instruction deletion to prevent iterator invalidation.
eraseFromParent() might invalidate the iterator, so when we're
walking the pointer to the next instruction in the SILBB we end up
crashing. In order to avoid this issue, collect a SmallVector of
instructions to remove, and defer the actualy removal after we
iterated the whole SILBasicBlock, as we know it's safe.

Fixes SR-6215.
2017-10-26 11:13:01 -07:00
Slava Pestov
c272d41e2f Re-apply "SIL: Remove special meaning for @_semantics("stdlib_binary_only")"
With -sil-serialize-all gone, this no longer means anything; just
don't declare the function as @_inlineable instead.

Fixes <rdar://problem/34564380>.
2017-10-04 14:07:52 -07:00
Jordan Rose
aab5f7aa4f Revert "SIL: Remove special meaning for @_semantics("stdlib_binary_only")" (#12270)
It still affects StdlibUnittest, which is still using -sil-serialize-all.
2017-10-04 12:49:21 -07:00
Slava Pestov
0fad13eeba SIL: Remove special meaning for @_semantics("stdlib_binary_only")
With -sil-serialize-all gone, this no longer means anything; just
don't declare the function as @_inlineable instead.

Fixes <rdar://problem/34564380>.
2017-10-03 13:48:22 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Erik Eckstein
ba1a5f9cae Produce more efficient code for the init(rawValue: String) constructor of string enums, part 2.
Use a dictionary for string lookup, which is initialized the first time the constructor is called.
This is more efficient than just iterating of the string table.

Unfortunately it's still not as fast as the original version (where all the string comparisons are inlined into the constructor) for enums with < 100 strings.
But this will improve once we can pass the string and string table as borrowed parameters and we can reduce the ARC overhead.
2017-09-18 17:50:24 -07:00
Erik Eckstein
fb935a3d49 SIL: support statically initialized StaticString globals
The main part of the change is to support the ptr_to_int builtin in statically initialized globals. This builtin is used to build a StaticString from a string_literal.
On the other hand I removed the support of the FPTrunc builtin, which is not needed anyway (because it can be constant propagated).
2017-09-18 17:50:24 -07:00
Erik Eckstein
09388a51ec GlobalOpt: don't statically initialize ObjC objects
fixes rdar://problem/34117396
2017-08-31 14:39:32 -07:00
Erik Eckstein
cbcde4ed35 GlobalOpt: don't convert arrays with empty element type into statically initialized objects
This doesn't play well with the minimum stride of 1 for empty types.
2017-08-30 14:24:15 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00