Commit Graph

9332 Commits

Author SHA1 Message Date
Michael Gottesman
867fab2d00 Make sure to only verify indirect results if the number of parameters to the function is > 1.
Swift SVN r22120
2014-09-19 05:04:59 +00:00
Michael Gottesman
04aaf791f0 [verifier] Make sure all SILFunctions only have one out parameter and that out parameter is the first argument to the function.
This is already an assumption in SILFunctionType:

  bool hasIndirectResult() const {
    return !getParameters().empty()
      && getParameters()[0].isIndirectResult();
  }
  SILParameterInfo getIndirectResult() const {
    assert(hasIndirectResult());
    return getParameters()[0];
  }

This just bakes the invariant into the IR so it is clear when writing tests that
this is not an issue.

I also updated function_ref and partial_apply to have the same such checks. This
should handle the majority of the cases.

Swift SVN r22119
2014-09-19 04:37:40 +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
John McCall
75050f8166 Generate an implicit 'materializeForSet' accessor
along with getters and setters.

Just generate it for now.

Swift SVN r22011
2014-09-17 08:08:03 +00:00
Manman Ren
afa7c440ba [Global Opt] update Parser and Printer to handle InitializerF for SILGlobalVariable.
Swift SVN r21984
2014-09-16 21:55:13 +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
37c9618abb SIL: Add comments to reinstate early exit on address-only aggregate fields when we have a Sema check for value type recursion.
Swift SVN r21977
2014-09-16 18:14:10 +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
2c50e5c1b2 Move cl::opt in SILFunction into assert builds
Swift SVN r21935
2014-09-13 02:45:25 +00:00
Arnold Schwaighofer
36ad6d2faa ValueBase: Add getParentBB api
Swift SVN r21925
2014-09-12 21:05:21 +00:00
Arnold Schwaighofer
666f8f0f4a Move view-cfg-only-for-function into SILFunction::viewCFG
Swift SVN r21923
2014-09-12 21:05:19 +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
Michael Gottesman
4647eb9601 Create RCIdentityAnalysis a cache for stripRCIdentityPreservingOps.
The cache is needed to ensure we do not run into compile time problems once we
start looking through Phi Nodes.

The analysis is currently disabled and just returns
SILValue::stripRCIdentityPreservingOps. I am going to thread it through the rest
of the passes that use that call. Then I am going to hide
stripRCIdentityPreservingArgs. Finally post OzU, I am going to enable the pass.

rdar://18300069

Swift SVN r21891
2014-09-11 21:51:29 +00:00
Manman Ren
a952c556c9 [Global Opt] replace GlobalAddrInst with SILGlobalAddrInst.
Update SILGen to create SILGlobalVariable and SILGlobalAddrInst instead of
GlobalAddrInst. When we see a definition for a global variable, we create
the corrsponding SILGlobalVariable definition.

When creating SILGlobalVariable from a global VarDecl, we mangle the global
VarDecl in the same way as we mangle it at IRGen. The SILLinkage is also
set in the same way as we set it at IRGen.

At IRGen, we use the associated VarDecl for SILGlobalVariable if it exists,
to have better debugging information.

We set the initializer for SILGlobalVariable definition only.

We also handle SILGlobalAddrInst in various SILPasses, in the similar way
as we handle GlobalAddrInst.

rdar://15493694


Swift SVN r21887
2014-09-11 20:00:39 +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
John McCall
4e485850c5 Remove some dead code: captured variables can never be
properties at all, much less @objc properties.

Swift SVN r21732
2014-09-05 00:14:52 +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
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
Michael Gottesman
2b4d7f72a2 [g-arc-opts] Look through enum literal instructions.
The enum literal instruction has the same reference identity as its payload if
it has a payload.

<rdar://problem/18195085>

Swift SVN r21644
2014-09-02 16:03:11 +00:00
Chris Lattner
0275a37935 enhance the SIL is_nonnull instruction to work with values of function type. This
isn't used yet.


Swift SVN r21636
2014-09-02 01:06:07 +00:00
Chris Lattner
14278ea865 DynamicMethodBranchInst and DynamicMethodInst both only work on @objc methods,
so add these verifier checks back.  The rest of the changes I made are 
still correct/useful, as they remove pointless unchecked_ref_cast's to
Builtin.UnknownObject, which generates cleaner SIL.


Swift SVN r21631
2014-09-01 19:34:57 +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
fb04e9082b [g-arc-opts] unchecked_enum_data is always a ref count identity preserving operation, always strip them off.
Originally I was using the notion of layout compatible to define the notion of a
ref count identity preserving operation. This is too restrictive of a definition
since layout compatible implies that the operation does not change the memory
location being pointed at. On the other hand, we just care that the ref counts
are the same.

rdar://18189329

Swift SVN r21613
2014-08-31 18:08:29 +00:00
Joe Groff
ea26f65b62 SIL/IRGen: Implement Builtin.bridgeFromRawPointer for arbitrary bridgeable object types.
Any single-refcounted-pointer type can be cast from a raw pointer. Also generalize unchecked_ref_cast to cast among arbitrary single-refcounted-pointer types. Fixes rdar://problem/18184883.

Swift SVN r21609
2014-08-30 17:07:18 +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
7dfe17798c fix the implementation of some verifier logic (which never considered
address only arguments to DynamicMethodBranchInst) and reenable a verifier
check I accidentally disable in my last patch.


Swift SVN r21520
2014-08-28 07:42:46 +00:00
Chris Lattner
44a1eb7715 Rework SILGen of optional methods to work with non-@objc situations:
- Split getSelfTypeForDynamicLookup into two pieces, and generalize it
    to work on non-loadable protocols.
  - Change dynamic_method_branch to take its argument as a protocol of any
    protocol type, instead of as something of UnownObject type.
  - Teach emitForcedDynamicMemberRef to only do its peephole optimization for
    @objc cases, since it is special behavior of objc_msgSend.
  - enhance emitDynamicPartialApply & emitDynamicMemberRefExpr to emit the
    proper project_existential instruction (not a _ref) when dealing with a
    non-classbound protocol.

Change the verifier to allow DynamicMethodBranchInst to work on non-@objc
protocol members.

This eliminates a bunch of pointless unchecked_ref_cast's in the generated
SIL for existing code, but this got squashed at IRGen time anyway, so no
real change for anything that sema permits.



Swift SVN r21519
2014-08-28 07:37:18 +00:00
Chris Lattner
dc7c565af8 further generalize dynamic_method and dynamic_method_br: instead of having them force
the subject to "Builtin.UnknownObject", just traffic in the protocol type directly.


Swift SVN r21516
2014-08-28 05:41:35 +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
Jordan Rose
eef29dac21 -emit-sil: Don't print AST decls if we haven't type-checked the entire module.
The AST printer can't handle non-type-checked decls, so for now just only
print SIL if we're in -primary-file mode. That doesn't result in parseable
SIL, but it's better than crashing because we tried to print something
irrelevant from another file.

Swift SVN r21500
2014-08-28 00:32:38 +00:00
Joe Groff
4c65da9772 Make Builtin.bridgeToRawPointer work with class existentials.
It should definitely work with AnyObject, but it can also apply to any class existential by just shedding the witness tables. This lets us eliminate a bunch of unsafeBitCasts from the alimentary canals of the stdlib.

Swift SVN r21472
2014-08-27 00:58:42 +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
Erik Eckstein
9f49c213e9 Add an option -sil-print-no-color to disable coloring the SIL output.
This is useful when dumping the SIL in the XCode console, which does not interpret the color codes.



Swift SVN r21417
2014-08-22 18:46:45 +00:00
Michael Gottesman
9e55da4c92 [sink] Teach SILInstruction::isIdenticalTo how to handle retain_value. This is why we have not been sinking retain_value from predecessors.
I also cleaned up some code in InstructionIdentityComparer. We compare operands
before we hit the comparer, so we don't need to check operand equality there.

Swift SVN r21359
2014-08-21 16:16:13 +00:00
Michael Gottesman
ae0ff91ff3 Teach the various forms of stripping to ignore single predecessor args from br and cond_br.
This is effectively looking through a no-op. So it makes sense to always look
through them if we can.

<rdar://problem/18038959>

Swift SVN r21343
2014-08-21 05:16:45 +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
87d1c91394 [g-arc-opts] Look through non phi rc identity preserving arguments.
rdar://18070340

Swift SVN r21329
2014-08-20 23:40:50 +00:00