Commit Graph

1693 Commits

Author SHA1 Message Date
Dmitri Hrybenko
94541a5ced Revert "Change select* instructions so that all of them have the same tail allocated"
This reverts commit r24159 because it breaks building the stdandard
library.

Swift SVN r24161
2014-12-28 08:04:45 +00:00
Michael Gottesman
a6bd0cce0f Change select* instructions so that all of them have the same tail allocated
memory layout and add a SelectInst API that allows for one to access select inst
operands when one does not care about what the cases actually are.

Previously select_enum, select_enum_addr had the following memory layout:

  [operands], [cases]

In constrast, select_value had the following layout:

  [operand1, case1, operand2, case 2, ...]

The layout for select_value makes it impossible to just visit operands in a
generic way via a higher level API. This is an important operation for many
analyses such as AA on select insts.

This commit does the following:

1. Adds a new abstract parent class for all select instructions called
SelectInst.
2. Adds a new templated implementation parent class that inherits from
SelectInst called SelectInstBase. This handles the complete implementation of
select for all types by templating on CaseTy.
3. Changes SelectEnumAddrInst, SelectEnumInst, SelectValueInst to be thin
classes that inherit from the appropriately specialized SelectInstBase.

I left in SelectEnumInstBase for now as a subclass of SelectInstBase and parent
class of SelectEnum{,Addr}Inst since it provides specific enum APIs that are
used all over the compiler. All of these methods have equivalent methods on
SelectInstBase. I just want to leave them for a later commit so that this commit
stays small.

Swift SVN r24159
2014-12-27 05:33:18 +00:00
Adrian Prantl
b4c7b90c4a Fix rdar://19309057 a little harder. ArtificialLocation cannot be used
after we emitted the return block.

Swift SVN r24036
2014-12-19 19:01:43 +00:00
Adrian Prantl
f857ab6bc9 Explicitly mark unified trap blocks with an artificial location.
Restores previous behavior / buildbot breakage.
<rdar://problem/19309057> swift/test/DebugInfo/trap-optimized.swift is failing after stdlib/codegen changes

Swift SVN r24035
2014-12-19 18:02:48 +00:00
John McCall
5c8fbc704c Add SIL instructions to convert between thin functions
and raw pointers.

Swift SVN r23992
2014-12-17 22:23:15 +00:00
John McCall
f361d8782e Allow generic parameters to be fulfilled by an
arbitrary parameter, not just self/Self.

Swift SVN r23912
2014-12-13 06:29:42 +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
John McCall
dd07c8ca10 Add 'mark_dependence', which indicates that an address
or pointer depends on another for validity in a
non-obvious way.

Also, document some basic value-propagation rules
based roughly on the optimization rules for ARC.

Swift SVN r23695
2014-12-04 22:38:09 +00:00
Adrian Prantl
3202823f3e Debug info: Emit the actual types for specialized variables instead of
their generic type.

NFC for unoptimized code, testcase for optimized code will come with
rdar://problem/18709125.

Swift SVN r23676
2014-12-04 02:13:46 +00:00
Erik Eckstein
c1c11216bc fix: cond_br with identical true/false blocks and differing block arguments generate illagal llvm phi-nodes.
Phi nodes may not have identical predecessors and differing values.

This should fix <rdar://problem/18568272> Swift compiler fails with "PHI node has multiple entries for the same basic block with different incoming values!"



Swift SVN r23580
2014-11-25 09:18:06 +00:00
Adrian Prantl
4016c57819 Debug info: Make a store that is part of the initial setup of a frame
variable part of the function prologue by omitting its location.

Fixes <rdar://problem/18989457> Xcode 6.2 6C86C (lldb-320.4.157) : po self returns error: Execution was interrupted, reason: EXC_BAD_ACCESS

Swift SVN r23569
2014-11-24 01:06:18 +00:00
Joe Groff
01da305569 Factor out a TypeBase::hasDependentProtocolConformances() method.
Make it easier to get the "do I expect null ProtocolConformance* pointers" logic right. Audit existing uses of is<ArchetypeType>() for this purpose.

Swift SVN r23479
2014-11-20 18:43:17 +00:00
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Andrew Trick
32b104abb2 Silence unannotated fall-through warnings.
Swift SVN r23342
2014-11-15 00:37:35 +00:00
Joe Groff
d178b88847 IRGen: Don't reference ivar offsets for empty ObjC ivars.
They don't need storage because they're empty, so we don't emit their offsets, but we still emitted references to their offset variable. Fix this by lowering ref_element_addr to an undef for empty fields.

Swift SVN r23317
2014-11-14 02:11:25 +00:00
Michael Gottesman
2e37bef050 [irgen] Use object_getClass instead of object_getType() when lowering objc existential_metatype instructions.
Previously, we were not respecting the representation of the existential
metatype and were treating all existential metatypes as if the metatype
was a thick metatype. Instead now we properly grab the instance of the
class from the existential and then query the runtime for the
objc_class. This is done via the new entrypoint
emitHeapMetadataRefForUnknownHeapObject.

I also modified emitHeapMetadataRefForHeapObject to use
emitHeapMetadataRefForUnknownHeapObject instead of
emitLoadOfObjCHeapMetadataRef since the latter does not properly handle
tagged pointers. This bug was found on inspection when Joe and I were
talking about this change.

rdar://18841292

Swift SVN r23308
2014-11-13 19:36:00 +00:00
Adrian Prantl
1be7553d39 Debug info: unwrap promoted inout variables and prevent a double-deref of
inout variables.

Swift SVN r23276
2014-11-12 18:06:21 +00:00
Adrian Prantl
4244c45f37 Debug info: Emit byref captures as indirect.
<rdar://problem/15851064> Variables captured by inner functions are described oddly and often incorrectly

Swift SVN r23258
2014-11-12 01:28:51 +00:00
Joe Groff
5ed6e2731b IRGen: Code gen for casts to existential metatype.
The code path here is mostly the same as the class cast case--we have to test the ObjC class (if it is a class) against any ObjC protocols, then look up conformances for the native protocols.

Swift SVN r23184
2014-11-09 02:40:25 +00:00
Joe Groff
f229840161 IRGen: Code generation for general class existential casts.
Emit a helper that invokes conformsToProtocol the appropriate number of times for the destination protocol type.

Swift SVN r23176
2014-11-08 04:53:46 +00:00
Joe Groff
a832c6b708 IRGen: Strip out support for address casts from the value cast path.
Swift SVN r23135
2014-11-06 21:47:21 +00:00
Erik Eckstein
ec4accfda8 Optimize IRGen of select_num which maps the enum tag trivially to an int value.
This generates a simple int-cast instead of a switch.



Swift SVN r23117
2014-11-05 15:43:10 +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
03a5d72a35 Get rid of virtual functions. Use CRTP instead.
Swift SVN r23057
2014-11-01 06:34:30 +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
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Adrian Prantl
34b93f1219 Remove a stale and confusing comment.
Swift SVN r22976
2014-10-28 01:49:07 +00:00
Joe Groff
5a2f48e3be Add a Builtin.BridgeObject type.
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:

- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
  Builtin.BridgeObject

  Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
  "ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
  interfere with the reference identity of the resulting value. In other words,
  it is undefined behavior unless:

    castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref

  This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
  object pointer, "bits" must not have any non-spare bits set (unless they're
  already set in the pointer value). The native discriminator bit may only be set
  if the object is Swift-refcounted.

- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T

  Extracts the reference from a BridgeObject.

- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word

  Presents the bit pattern of a BridgeObject as a Word.

BridgeObject's bits are set up as follows on the various platforms:

i386, armv7:

  No ObjC tagged pointers
  Swift native refcounting flag bit: 0x0000_0001
  Other available spare bits:        0x0000_0002

x86_64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
  Swift native refcounting flag bit: 0x0000_0000_0000_0002
  Other available spare bits:        0x7F00_0000_0000_0004

arm64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
  Swift native refcounting flag bit: 0x4000_0000_0000_0000
  Other available spare bits:        0x3F00_0000_0000_0007

TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.

Swift SVN r22880
2014-10-23 00:09:23 +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
Dmitri Hrybenko
c371dd49dd Remove unused function
Swift SVN r22816
2014-10-17 20:35:21 +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
c459a57222 SILGen: Allow castFromNativeObject to AnyObject.
And in IRGen, fix up pointer cast codegen to work with types that explode to single scalars while being stored in named structs. Fixes rdar://problem/18604262

Swift SVN r22671
2014-10-10 18:55:21 +00:00
Adrian Prantl
6bf12fa2b5 Avoid emitting -Onone shadow copies twice and fix a notorious line table
issue as a side-effect.
<rdar://problem/16963544> TestSwiftStepping fails

Swift SVN r22647
2014-10-09 23:51:58 +00:00
Adrian Prantl
aa3241ea97 Remove the isAvailableExternally guards for emitting debug info. Functions
with external availability are emitted into IR so they can be inlined
by LLVM, hence we do want debug information present there.

Swift SVN r22624
2014-10-09 18:04:32 +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
Adrian Prantl
5f0439cfb0 Debug info: Emit proper locations/scopes also for available_externally
functions. Otherwise LLVM will get confused when inlining these functions.

Swift SVN r22604
2014-10-08 16:25:38 +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
Adrian Prantl
8d806d0aa5 Enable emission of debug locations for externally available functions.
This fixes LLVM assertions as outlined in the comment.

Swift SVN r22568
2014-10-07 19:26:40 +00:00
Adrian Prantl
2f14ba965d Rename variable for consistency.
Swift SVN r22566
2014-10-07 17:33:36 +00:00
Joe Groff
782833f054 SIL: Remove the project_existential* instructions.
Swift SVN r22457
2014-10-02 04:06:10 +00:00
Joe Groff
00fd417bd2 IRGen: Remove support for existential methods.
Eliminate support code for lowering protocol_method instructions, and eliminate ExtraDataKind::Metadata, which is no longer needed now that SIL provides all the necessary type information at the call site.

Swift SVN r22451
2014-10-02 00:11:54 +00:00
Joe Groff
3a606b9eb8 SIL: Drop the protocol_method instruction.
Swift SVN r22446
2014-10-01 23:35:41 +00:00