Commit Graph

6634 Commits

Author SHA1 Message Date
Erik Eckstein
c16c510167 Set SILLinkage according to visibility.
Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
2014-09-23 12:33:18 +00:00
Joe Groff
232cec4b61 SIL: Rename TypeConverter::getInterfaceType{In,OutOf}Context
It extracts an interface type out of a contextual type, but the name made it sound like it put it into a context. NFC.

Swift SVN r22188
2014-09-22 21:56:47 +00:00
Erik Eckstein
1d2df530fd Remove redundant definition of getSpecializedLinkage
I don't know why this function was defined in TypeSubstCloner.
Now it just takes the equivalent implementation from Local.cpp.



Swift SVN r22173
2014-09-22 15:39:03 +00:00
Michael Gottesman
561ab6980e [simplify-cfg] Canonicalize enum_is_tag on Optionals to always be on Some by swapping cond_br arguments if we have a .None check.
Swift SVN r22158
2014-09-21 10:56:30 +00:00
Michael Gottesman
a30dbd1fc0 Add some helper methods to CondBranchInst for getting True, False operands and a swapSuccessor method.
Swift SVN r22157
2014-09-21 10:56:28 +00:00
Michael Gottesman
8d9e358ad4 [closure-spec] Use the signature of the closure's function_ref instead of the
arguments of the closure since if the closure is an external declaration, it
wont have a first BB.

Swift SVN r22114
2014-09-19 02:33:58 +00:00
Michael Gottesman
659a4a7daf Clean up whitespace errors. NFC.
Swift SVN r22112
2014-09-19 02:16:41 +00:00
Anna Zaks
782fac1d6a [SIL Unreachability] Do not report false positives in single statement closures
(I suspect SILLocation annotation code in other places is not aware of isImplicit() AST flag...)

Swift SVN r22110
2014-09-19 01:40:03 +00:00
Manman Ren
5ba1930a36 [Global Opt] add helper functions to analyze static initializer in SILGlobalVariable.
Also use the helper function to verify initializers for SILGlobalVariables.


Swift SVN r22082
2014-09-18 17:30:59 +00:00
Joe Groff
0279b570ac SILGen: Class-constrained generic bases are +1 for setters too.
Factor out the common logic here for future consistency. Fixes rdar://problem/18275858.

Swift SVN r22057
2014-09-18 02:31:11 +00:00
Manman Ren
53151b90bd [Global Opt] add SILFunction *InitializerF to SILGlobalVariable.
It is defaulted to nullptr. When it is set, we increment the SILFunction's
ref count to keep it alive.

It will be used in followon patches for globals that can be statically
initialized.


Swift SVN r21983
2014-09-16 21:50:56 +00:00
Joe Groff
041c179e01 SIL: Continue type lowering after address-only fields of aggregates.
Now that we rely on type lowering to catch recursive value types, this optimization is no longer valid. Fixes rdar://problem/18232757 (crash suite #015).

Swift SVN r21967
2014-09-16 04:55:44 +00:00
Arnold Schwaighofer
855657511a Document ValueBase::getParentBB
Swift SVN r21931
2014-09-12 21:12:11 +00:00
Arnold Schwaighofer
36ad6d2faa ValueBase: Add getParentBB api
Swift SVN r21925
2014-09-12 21:05:21 +00:00
Arnold Schwaighofer
73fd579edf SILInstruction: Add setArgument and setSelfArgument to ApplyInst
Swift SVN r21924
2014-09-12 21:05:20 +00:00
Michael Gottesman
4609513593 Remove SILValue::stripRCIdentityPreservingArgs and teach all uses of that method to use the new RCIdentityAnalysis.
Currently, the pass just calls a local version of that function. After OzU, I
will enable the full pass (which is currently disabled behind a flag).

Swift SVN r21894
2014-09-11 22:29:31 +00:00
Manman Ren
9491a0e190 [Global Opt] get ready to replace GlobalAddrInst with SILGlobalAddrInst.
We add two more fields to SILGlobalVariable: a VarDecl and a flag to see if this
is a declaration. VarDecl is mainly used for debugger support, it is also used
to check if the variable is weak imported.

We also modify the serializer to serialize the extra two fields.


Swift SVN r21883
2014-09-11 18:13:04 +00:00
Manman Ren
47272fd25f [Linkage] move getSILLinkage from GenDec.cpp to FormalLinkage.h.
So SILGen can call getSILLinkage in follow-on patches to replace GlobalAddrInst
with SILGLobalAddrInst.

No functionaility change.


Swift SVN r21881
2014-09-11 17:49:39 +00:00
Michael Gottesman
875fa02f98 Hide SILValue::stripSinglePredecessor{Args,RCIdentityPreservingArgs}.
These really should never have been exposed since they are internals to
SILValue.

Swift SVN r21868
2014-09-11 05:44:58 +00:00
Michael Gottesman
24c138f29c Move SILLoopInfo into swiftSIL from swiftSILAnalysis so that we match the separation in between analysis and IR entities.
This follows the model of dominance info and allows me to create reachability
methods on SILBasicBlock without creating dependencies from swiftSIL to
swiftSILAnalysis.

Swift SVN r21866
2014-09-11 03:03:06 +00:00
Michael Gottesman
d3b9679795 Add the method SILArgument::getIncomingValues and refactor SILArgument implementation from SILBasicBlock.cpp => SILArgument.cpp.
SILArgument::getIncomingValues() takes in an out array parameter and attempts to
gather up all values from the SILArguments parents predecessors whose value the
SILArgument could take on.

This will let me refactor the single predecessor handling code to also handle
multiple predecessors in a simple way.

Swift SVN r21864
2014-09-11 01:53:29 +00:00
Joe Groff
e004ad7df4 SIL: Carry AST types through init_existential instructions.
This is necessary to be able to properly stash values with nontrivial lowerings, such as metatypes and functions, inside existential containers. Modify SILGen to lower values to the proper abstraction level before storing them in an existential container. Part of the fix for rdar://problem/18189508, though runtime problems still remain when trying to actually dynamicCast out a metatype from an Any container.

Swift SVN r21830
2014-09-10 05:56:36 +00:00
Michael Gottesman
23afba6f7c Add in assert to make sure we only call SILArgument::getParameterInfo() on function arguments.
Swift SVN r21786
2014-09-08 21:10:44 +00:00
Michael Gottesman
225a5ca87b [func-sig-opts] Add the call SILFunction::spliceBody() to splice a function's body onto another function.
I also added code to ilist_traits so we can set the parent function on BB to be the new function.

Swift SVN r21729
2014-09-04 23:34:34 +00:00
Michael Gottesman
bc626ffec9 [func-sig-opts] Teach SILArgument how to look up its own SILParameter info.
Swift SVN r21726
2014-09-04 23:03:09 +00:00
Joe Groff
620170e795 SILGen: Handle 'init' witnesses less failable than their requirement.
This fix should also extend to the general case of witnesses that return non-optional for optional-returning requirements, when/if we support that.

Swift SVN r21721
2014-09-04 22:24:16 +00:00
Doug Gregor
c504086266 Revert r21707 "Remove the SIL is_nonnull instruction. It's no longer useful."
We want to be able to work around problems with non-failable
Objective-C initializers actually failing, which can happen when the
API audit data incorrectly marks an initializer as non-failable.



Swift SVN r21711
2014-09-04 17:26:34 +00:00
Doug Gregor
cdf94885ae Remove the SIL is_nonnull instruction. It's no longer useful.
Swift SVN r21707
2014-09-04 15:56:12 +00:00
Roman Levenstein
933e4bff17 [sil-simplify] Peepholes for (trunc (s_to_u (zext x)))->x and (trunc (u_to_s (zext (lshr x 1) Word -> Int64)) Int64 -> Word) -> (lshr x 1).
Related to rdar://17433082 and rdar://17406327

Swift SVN r21700
2014-09-04 10:27:08 +00:00
Michael Gottesman
1ba4322412 Make a small fix for LLVM style by inverting an if (condition) {return} into an if (!condition) {continue} return. NFC.
Swift SVN r21615
2014-08-31 18:18:38 +00:00
Michael Gottesman
ec7cc211cb [g-arc-opts] A struct_extract of the only non-trivial stored field of a struct is always a ref count identity preserving identity.
rdar://18189325

Swift SVN r21614
2014-08-31 18:08:30 +00:00
Michael Gottesman
8287d986d6 [patternmatch] Create matchers for all unary instructions that enable further matchers to be applied to the unary instructions argument.
Swift SVN r21539
2014-08-28 20:46:22 +00:00
Roman Levenstein
97014172b7 [sil-combine] String literal concatenation optimization. Constant-fold concatenation of string literals known at compile-time.
Addresses rdar://17033696.

Swift SVN r21526
2014-08-28 11:33:21 +00:00
Chris Lattner
9fa5d6de66 expose a SILBuilder::getTypeLowering helper method, NFC.
Swift SVN r21518
2014-08-28 07:04:08 +00:00
Chris Lattner
50979a2ff4 implement SILGen and IRGen support for witness table generation of non-objc optional
protocol requirements.  Not testable because sema doesn't allow these to exist.


Swift SVN r21513
2014-08-28 04:20:02 +00:00
Mark Lacey
51e710170a Fix typo in comment.
Swift SVN r21461
2014-08-26 19:49:46 +00:00
Erik Eckstein
99cc7603be Add an @inline(__always) function attribute.
This will let the performance inliner inline a function even if the costs are too high.
This attribute is only a hint to the inliner.
If the inliner has other good reasons not to inline a function,
it will ignore this attribute. For example if it is a recursive function (which is
currently not supported by the inliner).

Note that setting the inline threshold to 0 does disable performance inlining at all and in
this case also the @inline(__always) has no effect.



Swift SVN r21452
2014-08-26 00:56:34 +00:00
Erik Eckstein
2cd1c7df3a Add an isResilient check in SILType.
This is a wrapper for calling isResilient on nominal type decls.



Swift SVN r21449
2014-08-26 00:38:56 +00:00
Erik Eckstein
17c4a50766 Let the switch_enum instruction return a unqiue enum case for the default block, if possible.
This enables removal of more redundant switch_enum instructions, like

  switch_enum %0 : ..., default bb2
bb2:
  switch_enum %0 : ...




Swift SVN r21418
2014-08-22 18:51:56 +00:00
Mark Lacey
7b30e832e4 Move contents of CallGraph.h into CallGraphAnalysis.h.
Swift SVN r21393
2014-08-22 00:00:04 +00:00
Michael Gottesman
b30b212d04 Remove the term non-PHI and instead use SinglePredecessor.
Swift SVN r21340
2014-08-21 04:13:27 +00:00
Michael Gottesman
73434aa4fa Rename SwitchEnumInst::getBBCase => getUniqueCaseForDestination.
This matches the name for SwitchEnumInst::getCaseDestination() and includes the word
'unique' so that the name self documents.

I also removed a local function doing the same work in SimplifyCFG and changed
its user to use getUniqueCaseForDestination instead.

Swift SVN r21339
2014-08-21 04:06:19 +00:00
Michael Gottesman
0f7053bd01 Remove SILBasicBlock::getBBArgIndex(SILArgument *) in favor of SILArgument::getIndex().
The index is a property of the argument. There is no reason from a modeling
perspective to go through the BB to get it.

Swift SVN r21338
2014-08-21 04:06:19 +00:00
Michael Gottesman
6d7ace6013 Make sure that when stripping non phi rc identity preserving args from switch enums, we only strip off switch enum inst if our BB is mapped to the first payloaded case of the enum.
Swift SVN r21336
2014-08-21 03:46:26 +00:00
Michael Gottesman
96ef9814f5 Change CondBranchInst::getArgForDestBB() so that it returns SILValue() if the TrueBB and the False BB equal and so that it takes the SILArgument instead of the index.
Swift SVN r21335
2014-08-21 03:45:35 +00:00
Michael Gottesman
f3145119b9 Add SILValue::stripNonPHIArgs and SILValue::stripNonPHIRCIdentityPreservingArgs
for looking through SILArguments that are not PHIs in a load-store and ARC
optimizer context respectively.

Swift SVN r21328
2014-08-20 23:40:49 +00:00
Michael Gottesman
5038acfe09 Remove trailing whitespace. NFC.
Swift SVN r21327
2014-08-20 23:40:49 +00:00
Michael Gottesman
dec1bea98b Add support to SILArgument for finding the index of the SILArgument and a method on CondBranchInst to return the ith argument associated with a specific BB.
Together these allow you to find the specific cond_br argument that will be
passed to a BB by performing:

CBI->getArgForBB(BB, BBArg->getIndex())

Swift SVN r21326
2014-08-20 23:40:48 +00:00
Manman Ren
bc004b6b88 [Generic Specializer] handle specializing inherited conformance.
When we have a WitnessMethodInst in the original SILFunction and
self of the WitnessMethodInst will be replaced with the actual type
that has an inherited protocol conformance, we need to upcast the
lookup type of the WitnessMethodInst to make sure the lookup type
and the conformance type matches.

rdar://18068002


Swift SVN r21311
2014-08-20 18:36:56 +00:00
Arnold Schwaighofer
cd799f8e46 Revert "Add an inline(late) attribute"
This reverts commit r21286.

Discussions ongoing.

Swift SVN r21289
2014-08-19 18:15:25 +00:00