Commit Graph

67 Commits

Author SHA1 Message Date
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Michael Gottesman
03afdc5291 [caller-analysis] Reimplement CallerAnalysis ontop of findLocalApplySites.
Now the caller analysis can tell callers if it was able to find /all/ callers of
a callee.

NOTE: This does not change FSO itself yet.

rdar://41146023
2018-08-21 19:34:03 -07:00
John McCall
8613761487 Fix some edge cases when inlining coroutines.
The current inlining strategy doesn't support inlining coroutines
when there are multiple end_apply or abort_apply instructions in
the caller, so refuse to inline such cases.  Also, handle the case
where there are no yield instructions in the callee, which can
happen if e.g. the callee calls a no-return function.

I also simplified the code somewhat by removing the vestiges of the
code that tried to unify control flow with switches.

As an unrelated fix, suppress function signature optimization for
coroutines for now.
2018-08-20 19:23:11 -04:00
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
Mark Lacey
a5a1a63ed6 Silence a couple release build warnings about unused variables. 2018-07-12 07:52:02 -07:00
Slava Pestov
330be4a38e SILOptimizer: Remove 'unique ID' from FSO mangling 2018-07-11 15:29:45 -07:00
Adrian Prantl
fafdc510d0 Use compiler-generated location for func.-sig.-spec. thunks
Function signature specialization thunks don't have any correspondence
to code the user wrote.

rdar://problem/28859432
2018-06-27 13:14:32 -07:00
Huon Wilson
85424c0c3c [SILOptimizer] Properly disconnect the signature optimized function from a parent class.
The new function with an optimized signature _shouldn't_ have a non-trivial
classSubclassScope, even if the original function did, since the original
function (that becomes the thunk) is the symbol that serves that role.

Also part of rdar://problem/40738913
2018-06-27 12:09:14 +10:00
Huon Wilson
ed64fadb28 [SIL]/[SILOpt] Thunks and specializations shouldn't be connected to their parent class.
The "subclass scope" is meant to represent a connection to a vtable (and how
public something needs to be), for things that end up in class
vtables. Specializations and thunks are mostly internal implementation details
and do not end up there, so subclass scope is not applicable to them. This stops
the thunks and specializations being incorrectly public.

(Note, there are some thunks that _are_ public facing: if a function has its
signature optimized, the original entry point becomes a thunk, and this entry
point is what ends up in vtables etc., so needs to remain around, which means
keeping the same hacks for `private` members of an `open` class.)

Fixes rdar://problem/40738913.
2018-06-26 16:25:42 +10:00
Huon Wilson
413501b34a [SIL] Separate thunks from signature optimization from other thunks.
Signature optimization is slightly different to (most) other thunks, in that
it's taking an existing function and turning that into a thunk, rather than
creating a thunk that calls an existing function. These symbols can be public,
etc. and so need to be handled a bit different to other types of thunks.
2018-06-26 14:53:58 +10:00
Michael Gottesman
e02266d4fa [func-sig-opts][projection] All projection trees during the run on a function should share the same bump ptr allocator.
Found while reading code.
2018-06-11 20:51:26 -07:00
Michael Gottesman
bfc2dac336 [func-sig-opts] Split FunctionSignatureOpts.cpp into 3 files one for each of the operations it employs now.
This is one step along the way to splitting FSO into sub-transforms.
2018-06-04 00:49:14 -07:00
Michael Gottesman
30d4f45468 [func-sig-opts] Move FunctionSignatureOpts into the directory FunctionSignatureTransform in preparation for splitting it. 2018-06-04 00:49:14 -07:00