Commit Graph

143 Commits

Author SHA1 Message Date
Michael Gottesman
6fd616c95b Add SILValue::stripPointerProjections().
An address projection instruction is one of the following instructions:

1. struct_element_addr.
2. tuple_element_addr.
3. ref_element_addr.

This method takes in the given SILValue and continually searches up its
operand chain until it finds a non address projection, non-cast
value (where cast is defined as in SILValue::stripCasts()). The found
SILValue is then returned.

Swift SVN r12909
2014-01-24 07:30:34 +00:00
Michael Gottesman
15e087bb90 Added SILValue::stripCasts().
This method takes in a SILValue and returns the SILValue created by continually
moving up the operand chain of the SILValue until a non-cast instruction is hit.
The non-cast instruction is then returned.

Swift SVN r12906
2014-01-24 07:01:52 +00:00
Michael Gottesman
26f23c1ea8 Revert "Create is<INSERT_VALUE_RANGE_HERE> VALUE_RANGE predicates to SILValue.h"
This reverts commit r12749.

I did not know about the connection in between VALUE_RANGES and abstract SIL
Base types. Using those you can perform the same operation via the isa
operation.

Swift SVN r12763
2014-01-22 19:23:10 +00:00
Michael Gottesman
d509fb9093 Create is<INSERT_VALUE_RANGE_HERE> VALUE_RANGE predicates to SILValue.h
Thus if one wishes to match a method inst, instead of using a switch one could
just go isMethodInst(Kind) and get the appropriate result.

My hope is this will make life easier by allowing us to use less switches.

Swift SVN r12749
2014-01-22 18:17:27 +00:00
Joe Groff
402f4daa58 SILGen: Emit protocol witnesses.
Reuse John's abstraction thunking machinery in SILGenPoly to emit the abstraction change from a protocol requirement to a concrete witness. There are potentially two abstraction changes necessary; if a witness is generic, we need to reabstract again from the concrete substituted type of the witness to the generic witness function's original signature. This currently leads to a bunch of extra temporaries in cases where an argument or return gets unabstracted to a loadable value then reabstracted to a generic parameter, but optimizations should be able to clean this up. Protocol witnesses also have additional potential abstraction changes in their 'self' parameter: the 'self' parameter of the protocol requirement is always considered @inout, but class 'self' parameters are not; also, an operator requirement can be satisfied by a free function, in which case 'self' is discarded.

Also, fix a bug in return value thunking where, if the thunk could reuse its @out parameter as the @out parameter of the underlying function, we would not disable the cleanup we install on the result value, leading to the result getting overreleased.

Swift SVN r11245
2013-12-13 05:58:51 +00:00
Chris Lattner
e4c2231718 Add some operator-> implementations to iterators to match their operator*
implementations.


Swift SVN r10777
2013-12-04 06:04:07 +00:00
Michael Gottesman
301a42f140 Move SILInstruction::replaceAllUsesWith -> SILValue::replaceAllUsesWith.
This commit corrects, as Jim likes to put it, a "thinko".

Swift SVN r10760
2013-12-03 22:37:10 +00:00
Michael Gottesman
55a05b4951 [cse] Actually follow the directions from Hashing.h and put hash_value into swift namespace. Also remove a few const.
Swift SVN r10754
2013-12-03 21:38:17 +00:00
Michael Gottesman
faea4d5f60 [cse] Implement hash_value for SILValue and SILType.
*NOTE* I followed the hashing conventions used in the DenseMap hashing
implementations.

Swift SVN r10745
2013-12-03 01:07:54 +00:00
Michael Gottesman
9e77cf2103 Canonicalize the header guards for SILType.h and SILValue.h.
Swift SVN r10744
2013-12-03 01:06:14 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
Chris Lattner
f6d339526d fix typo
Swift SVN r9934
2013-11-04 22:43:52 +00:00
Jordan Rose
553983f584 Fix misuse of alignof, which returns alignment as 2^N instead of N.
If we constexpr'd some of the functions in MathExtras we could use
log2(alignof(T)), but for now just hardcode a literal "3".

Swift SVN r9928
2013-11-04 18:22:25 +00:00
Chris Lattner
db86f4dad1 Bump SILValue up to allow 2 bits of result number, enabling instructions to produce up to 4 results.
Swift SVN r9924
2013-11-04 18:02:08 +00:00
Chris Lattner
82567f9ffb SILValue is just a wrapper around its ValueAndResultNumber. Derive
the number of low bits available in it from the #bits in ValueAndResultNumber,
instead of computing it independently.


Swift SVN r9922
2013-11-04 17:54:42 +00:00
Chris Lattner
03e7b756d0 teach simplify-cfg to merge blocks connected by an uncond branch, when
the dest has no other predecessors.  This fires 6926 times on the stdlib.


Swift SVN r9794
2013-10-30 16:48:59 +00:00
Chris Lattner
681ad64db3 teach simplifycfg's dead block deletion to correctly handle blocks with
instructions that are used cross-block.


Swift SVN r9788
2013-10-30 14:23:51 +00:00
Chris Lattner
6c23f3e8f8 Add an important assert to ValueBase, to make it a hard error to delete
a value that still has uses.  Doing so leaves dangling pointers and is
unwise.  Nothing in the testsuite triggers this, but simplify-cfg can
on real code.


Swift SVN r9770
2013-10-29 23:44:51 +00:00
Chris Lattner
c118613de3 Fix SILValue use_iterators to type the user as a SILInstruction, not just a ValueBase.
There are no values other than instructions that can use other values.  BBArguments are
defs, not uses.  This eliminates a bunch of casts in clients that use getUser().


Swift SVN r9701
2013-10-27 23:32:14 +00:00
Chris Lattner
1687382e95 Checkpoint some progress on inout deshadowing, since I'm about to
take a direction change and remove it all. :-)


Swift SVN r8965
2013-10-07 17:18:21 +00:00
Joe Groff
82a18333ed SIL: Purge SpecializeInst.
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.

Swift SVN r8747
2013-09-28 00:15:45 +00:00
Michael Gottesman
85c7a0b5d9 Change SILValue::operator*()'s return type from ValueBase * -> ValueBase & to match the normal canonical implementation of operator*.
Thanks Dave A!

Swift SVN r8740
2013-09-27 21:07:44 +00:00
Michael Gottesman
01840d2011 Added operator->()'s brother operator*() to SILValue.
Swift SVN r8722
2013-09-27 05:24:00 +00:00
Anna Zaks
b073815e7d [SIL] Remove ValueBase::replaceAllUses, which should never have been added.
I’ve added it without understanding the full consequences. If a variant of this is added, it
should take a list of values as the argument. Currently, there is no use for it, so just remove it.

Swift SVN r7238
2013-08-14 22:01:58 +00:00
Anna Zaks
359695acbd [SIL] Add dropAllReferences and a mutable version of getAllOperands
Swift SVN r7236
2013-08-14 22:01:57 +00:00
Anna Zaks
342dff1c80 [SIL CCP] Add the early constant propagation pass skeleton.
The pass folds a single operation: int_sadd_with_overflow and issues an
error on detectable overflow.

Swift SVN r7204
2013-08-13 17:36:35 +00:00
John McCall
2eabba0faa Add a getUser() to ValueBase::use_iterator.
Swift SVN r6973
2013-08-07 03:21:11 +00:00
Joe Groff
cc45633714 SIL: Don't print instruction labels for value-less instructions.
Swift SVN r6756
2013-07-30 22:33:34 +00:00
Chris Lattner
496446ce64 Make all SIL objects that are print()-able, also raw_ostream insertable
with <<.  Use this to implement a DEBUG() dump in MemoryPromotion.cpp


Swift SVN r6412
2013-07-20 02:43:26 +00:00
Chris Lattner
f8c8eb1037 add some helper methods for IR passes to use.
Swift SVN r6407
2013-07-20 01:36:46 +00:00
Chris Lattner
3db9fff98f implement SILValue::replaceAllUsesWith, fix a linked list manipulation
bug in removeFromCurrent.  Clearly I would fail an interview manipulating
linked lists :-)


Swift SVN r5341
2013-05-25 18:39:37 +00:00
Joe Groff
5e2779b51e SIL: Uncurry function types within the Swift type system.
Remove uncurry level as a property of SILType/SILFunctionTypeInfo. During SIL type lowering, map a (Type, UncurryLevel) pair to a Swift CanType with the uncurried arguments as a Swift tuple. For example, T -> (U, V) -> W at uncurry level 1 becomes ((U, V), T) -> W--in reverse order to match the low-level calling convention. Update SILGen and IRGen all over the place for this representation change.

SILFunctionTypeInfo is still used in the SILType representation, but it's no longer load-bearing. Everything remaining in it can be derived from a Swift type.

This is an ABI break. Be sure to rebuild clean!

Swift SVN r5296
2013-05-24 01:51:07 +00:00
Chris Lattner
02f02fca0f [overpedantic] Get plurality right in the # users comment, printing:
%0 = tuple ()                                   // user: %1
  %1 = return %0 : $()

instead of "users".



Swift SVN r5268
2013-05-22 17:58:44 +00:00
Chris Lattner
38f19fed50 de-indent classes in this file and fit 80 columns. No functionality change.
Swift SVN r5264
2013-05-22 17:23:40 +00:00
Chris Lattner
1f971f88dd Remove the IsLoadable flag from SILType, and the isInvalid() state for SILType.
This frees up an extra bit in SILType, which we can expose to LLVM through
PointerLikeTypeTraits.  Use this bit in a PointerUnion, which allows simplifying
ValueBase, which happened to be the last use of the isInvalid() state.



Swift SVN r5218
2013-05-18 00:21:46 +00:00
Joe Groff
bcb49ce450 SIL: Key functions directly without SILConstant.
Replace 'constant_ref' with 'function_ref', which references a SILFunction directly, and 'global_addr', which references a global variable VarDecl. Get rid of the SILConstant-to-SILFunction mapping in SILModule and replace it with an ilist of SILFunctions. Allow SILFunctions to be 'external' by not having any blocks in their body. 

For now, SILFunctions still carry around their SILConstant "name", because name mangling and IRGen still rely on access to the original decl in order to recover IRGen information, which unfortunately leaves IRGen's CodeRefs in a gross, awkward intermediate state. Lifting mangling, AbstractCC, and other linkage attributes to SIL should clear up this up.

Swift SVN r4865
2013-04-23 23:29:04 +00:00
Joe Groff
a90338bddb IRGen: Compile builtin calls from SIL.
When lowering SIL builtin ConstantRefs, just stash away the FuncDecl, and pass that decl on to a tweaked version of emitBuiltinCall when the constant is applied.

Swift SVN r4736
2013-04-15 21:04:36 +00:00
Joe Groff
bc2abab6d1 SIL: Add SILValue::dumpInContext.
Dumps an instruction with its operands and users. Useful for debugging.

Swift SVN r4713
2013-04-12 16:36:25 +00:00
John McCall
8dca52a2b0 Enhance the verifier to verify some basic properties of uses.
Also, refactor it to make it completely painless to introduce
new checks at arbitrary levels in the hierarchy.

Swift SVN r4710
2013-04-12 05:39:02 +00:00
John McCall
7e15f0a557 Make SIL-visiting not have a default implementation, make classof
take a const ValueBase* instead of a SILValue, implement SILArgument
cases for a few visitors and opt others out explicitly, and assert
that classes in the SIL value hierarchy override their superclass's
classof.

Swift SVN r4705
2013-04-12 01:39:52 +00:00
John McCall
f9226a8178 Add a getAllOperands() method to SILInstructions.
Required some renaming of the internal field-selector constants
to avoid inadvertent shadowing.

Swift SVN r4703
2013-04-12 00:54:53 +00:00
Chris Lattner
a71bc3a78e rename Value -> SILValue, BasicBlock -> SILBasicBlock, BBArgument -> SILArgument.
Swift SVN r4594
2013-04-03 21:05:42 +00:00
Chris Lattner
fe23727891 rename Value.h -> SILValue.h, missed it in the last pass.
Swift SVN r4592
2013-04-03 18:47:32 +00:00