Commit Graph

328 Commits

Author SHA1 Message Date
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Mark Lacey
fa49f01edf Support CSE of thin_function_to_pointer/pointer_to_thin_function.
Fixes <rdar://problem/19285001>

Patch by Luqman Aden <luqman_aden@apple.com>.

Swift SVN r24604
2015-01-21 19:36:51 +00:00
Michael Gottesman
6d52d178c1 Move the subclasses of SILInstruction into a new file SILInstructions.cpp.
SILInstruction was getting large (~1700 loc). Now we have two files, one that is
~1000 loc and the other with ~700 loc.

Swift SVN r23937
2014-12-15 14:09:54 +00:00
John McCall
169e4fe319 Add Builtin.UnsafeValueBuffer, which provides opaque
storage for arbitrary values.

A buffer doesn't provide any way to identify the type of
value it stores, and so it cannot be copied, moved, or
destroyed independently; thus it's not available as a
first-class type in Swift, which is why I've labelled
it Unsafe.  But it does allow an efficient means of
opaquely preserving information between two cooperating
functions.  This will be useful for the adjustments I
need to make to materializeForSet to support safe
addressors.

I considered making this a SIL type category instead,
like $@value_buffer T.  This is an attractive idea because
it's generally better-typed.  The disadvantages are that:
- it would need its own address_to_pointer equivalents and
- alloc_stack doesn't know what type will be stored in
  any particular buffer, so there still needs to be
  something opaque.

This representation is a bit gross, but it'll do.

Swift SVN r23903
2014-12-13 01:27:12 +00:00
Erik Eckstein
3b9805b246 Disallow cond_br with identical destinations.
It avoids generation of llvm phi nodes with identical predecessors and differing values.
This change replaces my previous fix of this problem in r23580, where I handled it in IRGen.

There were some discussions about it with the conclusion that it's better to just disallow such cond_br instructions in SIL.
It makes the life easier for some SIL optimizations which can't deal with cond_br with identical destinations.

The original radar is <rdar://problem/18568272> Swift compiler fails with "PHI node has multiple entries for the same basic block with different incoming values!"



Swift SVN r23861
2014-12-11 15:03:49 +00:00
John McCall
3b4e0d307e Intrinsic support for pinning.
Using the intrinsics is obnoxious because I needed them
to return Builtin.NativeObject?, but there's no reasonable
way to safely generate optional types from Builtins.cpp.
Ugh.

Dave and I also decided that there's no need for
swift_tryPin to allow a null object.

Swift SVN r23824
2014-12-10 00:52:48 +00:00
Joe Groff
a247f5d98c SIL parser: Populate conformances of init_existential insns.
And fix some bugs with existential conformances, where we were creating a bogus conformance instead of just using null conformances like other code expects.

Swift SVN r23461
2014-11-20 02:43:23 +00:00
Arnold Schwaighofer
c322b3592d Add a data dependence between opened existential values and method_inst that 'use' them.
Before this patch there was no dependence visible to the optimizer between a
open_existential and the witness_method allowing the optimizer to reorder the
two instruction. The dependence was implicit in the opened archetype but this
is not a concept model by the SIL optimizer.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1 : $@cc(...)
  %4 = apply %3<...>(%2)

This patch changes the SIL representation such that witness_methods on opened
archetypes take the open_existential (or the producer of the opened existential)
as an operand preventing the optimizer from reordering them.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1,
                      %2 : $*@opened("...") FooProto : $@cc(...)
  %4 = apply %3<...>(%2)

rdar://18984526

Swift SVN r23438
2014-11-19 17:22:22 +00:00
Arnold Schwaighofer
e9d650d01c CSE: handle RefToBridgeObjectInst and BridgeObjectToRefInst
rdar://19009279

Swift SVN r23414
2014-11-18 21:46:43 +00:00
Andrew Trick
96688dea2f Silince unused variable warnings.
Swift SVN r23341
2014-11-15 00:37:34 +00:00
Michael Gottesman
fae31cbaa2 [dead-object-elim] Add SILInstruction::mayTrap(), change SILInstruction::mayHaveSideEffects() to call it, and change dead object elimination to call mayHaveSideEffects().
Note that I did not change any actual memory behavior. That will come via a
later cleanup phase. Since this is a correctness fix I wanted to only make
things more conservative.

rdar://18568601

Swift SVN r23311
2014-11-14 00:05:15 +00:00
Michael Gottesman
320abd73fb Remove trailing whitespace and fix up some code to use LLVM style. NFC.
Swift SVN r23310
2014-11-14 00:05:14 +00:00
Erik Eckstein
581a5d02f5 Some bug fixes in the SwitchValueInst and SelectValueInst implementations.
Currently these instructions are not generated, so the bugs didn't cause any problems.



Swift SVN r23301
2014-11-13 09:06:50 +00:00
Roman Levenstein
742a9bf717 Don't jumpthread blocks containing MethodInst instructions referring to objc methods, because we cannot build SSA for method values that lower to objc methods.
rdar://18940762

Swift SVN r23245
2014-11-11 20:25:43 +00:00
Roman Levenstein
3910c25da1 Minor re-factoring: Move the logic to decide if a given instruction can be (easily) duplicated into SILInstruction. So far it was mainly used by jump-threading related optimizations. But it could be generally useful, or at least generally important, to optimizations that want to duplicate code.
Swift SVN r23213
2014-11-10 23:15:07 +00:00
Erik Eckstein
da9f08aec8 Replace the default-entry with a corresponding case-entry in select_enum[ _addr], if possible.
This is exactly the same thing as I did for switch_enum.



Swift SVN r23116
2014-11-05 12:48:11 +00:00
Roman Levenstein
c8d180e660 Generalize the switch_int instruction into switch_value instruction, which may switch on arguments of builtin integer types or function types. The later is required for implementing a more efficient speculative devirtualizaiton implementation. Implement lowering of switch_value into LLVM code. In case of integer operands, it reuses LLVM's switch optimizations. Support for switching on function types is not yet bullet-proof and will be refined in the subsequent patches.
rdar://18508812

Swift SVN r23042
2014-10-31 22:55:56 +00:00
Roman Levenstein
f016754ef9 Add a new select_value instruction. This instruction should be the equivalent of select_enum, just for builtin int types. Such an instruction is needed e.g. to efficiently implement conversions of Int raw values to C-like enums.
rdar://18812325

Swift SVN r23036
2014-10-31 20:44:11 +00:00
Erik Eckstein
743d6af4a4 Fix typo
Swift SVN r23004
2014-10-29 16:51:38 +00:00
Erik Eckstein
4df8f66b9a Replace the default-entry with a corresponding case-entry in switch_enum[_addr], if possible.
<rdar://problem/18709388> SimplifyCFG: Canonicalize default cases of covered switches to not use a default case




Swift SVN r23003
2014-10-29 14:56:34 +00:00
Erik Eckstein
3eea8e3052 Set SILLinkage of witness tables according to the protocol visibility.
This is the same change as already done for functions and globals
(for details see <rdar://problem/18201785>).




Swift SVN r22907
2014-10-24 09:02:05 +00:00
Joe Groff
3f23b82e6d SIL: Rename SILGlobalAddr to GlobalAddr.
All globals are SIL globals now.

Swift SVN r22827
2014-10-18 17:08:28 +00:00
Joe Groff
ea65d1e60b SIL: Remove the builtin_function_ref instruction.
Swift SVN r22797
2014-10-16 16:18:40 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Joe Groff
bb46f4bbd9 SIL: Remove the global_addr instruction.
It's no longer needed now that we always lower to SIL globals.

Swift SVN r22693
2014-10-12 17:19:06 +00:00
Joe Groff
a60a52d72e SIL: Add a "builtin" instruction to represent builtin invocations.
Modeling builtins as first-class function values doesn't really make sense because there's no real function value to emit, and modeling them this way complicates passes that work with builtins because they have to invent function types for builtin invocations. It's much more straightforward to have a single instruction that references the builtin by ID, along with the type information for the necessary values, type parameters, and results, so add a new "builtin" instruction that directly represents a builtin invocation. NFC yet.

Swift SVN r22690
2014-10-11 20:34:24 +00:00
Joe Groff
9205bf64cf SIL: Remove enum_is_tag.
Swift SVN r22616
2014-10-09 05:03:43 +00:00
Joe Groff
c2fc9f58b8 SIL passes: Work with select_enum instead of enum_is_tag.
Simplify binary switches to select_enum instead of enum_is_tag, and make a first attempt at changing passes over to recognize limited forms of select_enum instead of enum_is_tag. There is one case in test/SILPasses/simplify_cfg.sil I wasn't able to figure out, and there are a lot more general passes we could define in terms of select_enum.

Swift SVN r22615
2014-10-09 03:49:31 +00:00
John McCall
89e60f31aa Add protocol witness tables to existential metatype
layouts.  Introduce new SIL instructions to initialize
and open existential metatype values.

Don't actually, y'know, lift any of the restriction on
existential metatypes; just pointlessly burn extra
memory storing them.

Swift SVN r22592
2014-10-08 01:20:13 +00:00
Joe Groff
ca8b168188 SIL: Add select_enum and select_enum_addr insns.
Similar to LLVM's "select" instruction, the instruction picks one of its operands based on the case tag of an enum value.

Swift SVN r22578
2014-10-07 21:45:08 +00:00
Michael Gottesman
b4c06632e2 Add a helper method SILInstruction::replaceAllUsesWithUndef().
This should really be on ValueBase, but currently ValueBase does not
have access to a SILModule.

Swift SVN r22559
2014-10-07 00:53:56 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Joe Groff
782833f054 SIL: Remove the project_existential* instructions.
Swift SVN r22457
2014-10-02 04:06:10 +00:00
Joe Groff
be45322668 SIL: Drop the upcast_existential* instructions.
Swift SVN r22388
2014-09-30 16:11:54 +00:00
Joe Groff
c098645f34 SIL: Conformances relate to formal types, so change witness_method's lookup type to a CanType.
Should be NFC in practice, since only nominal types can currently conform to protocols anyway, but improves modeling of the system.

Swift SVN r22360
2014-09-29 20:44:00 +00:00
Joe Groff
152aa9e244 Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22345.

Swift SVN r22353
2014-09-29 13:46:41 +00:00
Joe Groff
1e343fb430 SIL: Drop the upcast_existential* instructions.
Swift SVN r22345
2014-09-28 19:24:33 +00:00
Joe Groff
0518f2067f Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22333.

Swift SVN r22337
2014-09-28 18:41:05 +00:00
Joe Groff
727c9b5ed7 SIL: Drop the upcast_existential* instructions.
Swift SVN r22333
2014-09-28 16:38:13 +00:00
Joe Groff
a3126706da SIL: Eliminate the dead 'alloc_array' insn.
Swift SVN r22292
2014-09-26 02:28:10 +00:00
Roman Levenstein
1f635d0510 Add a CSE support for 15 SIL instructions that were not covered by the CSE pass yet.
rdar://16652567

Swift SVN r22281
2014-09-25 11:44:51 +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
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
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
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
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
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
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
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