Commit Graph

44 Commits

Author SHA1 Message Date
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Meghana Gupta
6f9167c29e Serialize after high level passes for -emit-sib 2025-01-30 17:10:04 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Erik Eckstein
5bc036661c SIL optimizer: add the LetPropertyLowering pass
It lowers let property accesses of classes.
Lowering consists of two tasks:

* In class initializers, insert `end_init_let_ref` instructions at places where all let-fields are initialized.
  This strictly separates the life-range of the class into a region where let fields are still written during
  initialization and a region where let fields are truly immutable.

* Add the `[immutable]` flag to all `ref_element_addr` instructions (for let-fields) which are in the "immutable"
  region. This includes the region after an inserted `end_init_let_ref` in an class initializer, but also all
  let-field accesses in other functions than the initializer and the destructor.

This pass should run after DefiniteInitialization but before RawSILInstLowering (because it relies on `mark_uninitialized` still present in the class initializer).
Note that it's not mandatory to run this pass. If it doesn't run, SIL is still correct.

Simplified example (after lowering):

  bb0(%0 : @owned C):                           // = self of the class initializer
    %1 = mark_uninitialized %0
    %2 = ref_element_addr %1, #C.l              // a let-field
    store %init_value to %2
    %3 = end_init_let_ref %1                    // inserted by lowering
    %4 = ref_element_addr [immutable] %3, #C.l  // set to immutable by lowering
    %5 = load %4
2023-09-19 15:10:30 +02:00
Erik Eckstein
e5eb15dcbe Swift SIL: replace the set_deallocating instruction with begin_dealloc_ref
Codegen is the same, but `begin_dealloc_ref` consumes the operand and produces a new SSA value.
This cleanly splits the liferange to the region before and within the destructor of a class.
2023-09-19 15:10:30 +02:00
Erik Eckstein
63808be395 DefinitInitialization: convert begin_access instructions of initializations to a static accesses
In case of `var` initializations, SILGen creates a dynamic begin/end_access pair around the initialization store.
If it's an initialization (and not a re-assign) it's guanranteed that it's an exlusive access and we can convert the access to an `[init] [static]` access.

https://github.com/apple/swift/issues/66496
2023-06-14 07:17:56 +02:00
Erik Eckstein
6375647383 driver: add swift-frontend options to select the tool to run
Tool selection is primarily done by checking the executable (= symlink) name.
But sometimes (e.g. if the tool symlink is not there) it's useful to have an option for selecting the tool.
The selection option (e.g. -sil-opt) must be the first argument of swift-frontend.
2023-04-28 15:18:16 +02:00
Slava Pestov
1e8ce52736 SIL: Strip [serialized] flag from functions even at -Onone
While the comment is correct to state that this won't enable any
new optimizations with -Onone, it does enable IRGen's lazy
function emission, which is important for 'reasync' functions,
which we don't want to emit at all even at -Onone.

This fixes debug stdlib builds with the new reasync versions
of the &&, || and ?? operators.
2021-04-08 01:47:27 -04:00
Michael Gottesman
91317c723c [ownership] Make whether or not we serialize in OSSA form based off of the flag -enable-ossa-modules.
I added a change to CMake so that the stdlib still gets the option passed in so
should be NFC.
2021-02-22 19:07:45 -08:00
Michael Gottesman
57654da4db [ownership] On non-Darwin platforms start serializing the stdlib in OSSA as well.
I had to fix a memory corruption bug (see previous commit) to land this. But now
that it is fixed, we are ready!
2021-02-17 15:59:00 -08:00
Michael Gottesman
dd6439d31e [ownership] Change the stdlib to serialize code in ossa form on Darwin.
There is some sort of ASAN issue that this exposes on Linux, so I am going to do
this on Darwin and then debug the Linux issue using ASAN over the weekend/next
week.
2021-02-12 23:20:17 -08:00
Michael Gottesman
4fd45930f8 [sil-optimizer] At -Onone serialize when running the Onone optimization pipeline instead of after running SIL passes.
NOTE: This is not in the mandatory passes (which run before this). This will
enable me to strip out ownership after we serialize without touching frontend
code. It also makes Onone and O use the same code paths for serialization
instead of one happening in the driver (Onone today) and the other in a SIL pass
(-O, -Osize).

The reason that I updated the sil-func-extractor test is that I found a bug in
how we emit sib files, namely if you try to emit a sib file to stdout, the
llvm-bcanalyzer flags it as malformed. If I output the .sib into a file rather
than trying to use stdout, everything works.
2019-01-14 10:33:58 -08:00
Michael Gottesman
fd4828e40a Eliminate -assume-parsing-unqualified-ownership-sil from tests.
I am doing this separately from the actual change to eliminate the option to
make it easier to review.
2018-12-19 12:54:13 -08:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Andrew Trick
3992a8c94f Print and parse the [canonical] function attribute. 2018-02-27 09:53:13 -08:00
Joe Shajrawi
b0fdadb3d2 Devirtualizer: disable the “effectively final” optimization if a function is inlinable.
The devirtualizer performs two optimizations:

- If a value is known to have an exact class type, ie it is the result of an alloc_ref, we can devirtualize calls of *non-final* methods, because we know we’re calling that specific method and not an override.

- If a method is known to be “effectively final” (it is not open, and there are no overrides inside the module) we can devirtualize it.

However the second optimization needs to be disabled if a function is inlinable (F->getResilienceExpansion() == ResilienceExpansion::Minimal).
2018-02-20 16:06:01 +02:00
Slava Pestov
2584a4878e Sema: Disallow inlinable initializers on non-fixed-layout types even in non-resilient builds
This is technically a source break, but the @_fixed_layout attribute
is not official yet. If anyone really cares, we can make this
conditional on -swift-version 5 later, but I'd rather not.

This change is necessary so that we can give property initializers
non-public linkage. Currently they are public, because they can be
referenced from inlinable initializers.

Now that property initializers inside a @_fixed_layout type can
only reference public symbols, they no longer have to be public,
but making that change requires a bit more work.
2018-01-12 19:03:49 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Pavel Yaskevich
170ccbd36d [Mangling/ABI] NFC: Fix Frontend/APINotes/Index tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Roman Levenstein
74915682cb Update tests after the removal of -sil-serialize-vtables 2017-10-21 19:18:15 -07:00
Roman Levenstein
35a624bb15 Update tests after removing -sil-serialize-witness-tables 2017-10-20 19:45:29 -07:00
Roman Levenstein
06efb77e4e Fix tests 2017-10-05 15:51:32 -07:00
Roman Levenstein
dd85e69e7f Update the tests after removing the -sil-serialize-all option 2017-10-04 14:20:53 -07:00
John McCall
ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
Andrew Trick
fa70d90b5e [Exclusivity] Update SILGen tests for dynamic access markers. 2017-05-31 21:43:00 -07:00
Max Moiseev
3cbcd716f5 Merge branch 'master' into new-integer-protocols 2017-03-31 10:03:20 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Max Moiseev
09af9ae4bc Fixing tests for Linux 2017-03-23 11:16:35 -07:00
Max Moiseev
8a8e27f706 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-03-22 12:51:19 -07:00
Max Moiseev
b9fb3badc8 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-03-22 12:30:24 -07:00
Erik Eckstein
c4a11f4c92 tests: remove the now unused option -new-mangling-for-tests 2017-03-22 11:28:43 -07:00
Erik Eckstein
2a55b26e46 Mangling: enable new mangling for symbols 2017-03-16 12:04:08 -07:00
Max Moiseev
835b8809d2 Merge branch 'master' into new-integer-protocols 2017-03-07 16:18:54 -08:00
Slava Pestov
32316559f8 AST: Stored property accessors on non-Objective-C derived classes can be transparent
In 74d979f0ac, the policy was changed
so that only value type accessors are ever marked transparent, and
not class accessors.

This was intended to fix a bug where inlining an accessor of an
Objective-C-derived class across module boundaries caused a linker
failure because the accessor referenced a field offset variable,
which has hidden visibility.

However, this also caused a performance regression for Swift native
classes. Bring back the old behavior for Swift native classes in
non-resilient modules.

Fixes <rdar://problem/29884727>.
2017-02-14 22:35:27 -08:00
Max Moiseev
90ef26824f Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-26 15:28:42 -08:00
Erik Eckstein
1d3724666f tests: convert about 400 tests to the new mangling by using the -new-mangling-for-tests option
When the new mangling is enabled permanently, the option can be removed from the RUN command lines again.
2017-01-24 15:27:45 -08:00
Max Moiseev
e1de9fcf0c More test fixes 2017-01-09 16:17:21 -08:00
Erik Eckstein
74d979f0ac SILGen: Don’t make class accessors transparent.
Because when they are inlined they might access hidden symbols in another module, like the field offset variable.

fixes rdar://problem/29707641
2016-12-19 17:02:09 -08:00
Jordan Rose
5dc2702d5f [test] Re-enable test that was previously order-dependent.
It looks like Saleem fixed it a while ago, but then it got re-disabled.

rdar://problem/25498105
2016-12-14 20:05:13 -08:00
Michael Gottesman
6a5f54e59f [sil-func-extractor] Add support for reading from a file a list of functions to preserve.
This will allow for greater scriptability.
2016-12-08 19:49:59 -08:00
Michael Gottesman
c12aeabd90 [sil-func-extractor] Add support for emitting sib files. 2016-12-08 18:29:33 -08:00
Michael Gottesman
0bfda96ace [sil-func-extractor] Teach sil-extract to extract a list of functions and the inverse of a list of functions. Also rename to sil-func-extractor to make it clearer what it is doing.
This will allow for modules to be split from the command line using a script.

The one thing that is missing from this still is that it does not handle shared
functions in IMO a satisfactory way. Given that we are splitting a module, my
feeling that the correct way to do this is to create a public shim for the
shared function in the module that the shared function gets put in and let all
other users use that entry point.

But I need to think about this a bit more.
2016-12-08 18:29:33 -08:00