[swift-dev] SR-5403 / Memory Optimization Opportunity (Load/Store forwarding)

Johannes WeiƟ johannesweiss at apple.com
Mon Jul 10 12:56:24 CDT 2017


Hi Michael,

Firstly: if swift-dev is not the right place for me to ask silly questions, please let me know :).

Thanks very much for all your pointers on the JIRA [1] ticket. I was just trying to get started and already have a few questions. Apologies, they're very basic as I'm just getting started with the Swift compiler source and tooling.

The first question is just about the tooling: I got sil-opt to run with an invocation like this:

   swiftc -emit-module -O test.swift
   sil-opt -sdk $(xcrun --show-sdk-path) test.swiftmodule

Now you advise to run the '-debug-only=sil-redundant-load-elim' so I tried

   sil-opt [...] -debug-only=sil-redundant-load-elim

but it doesn't seem happy with that. Did I misunderstand how to pass this option?


My second question actually relates to your first suggestion: 'creating a simple test that performs a store, then passes the address to an in_guaranteed function and then reloads the value'

I read up about @in_guaranteed and I managed to make a @in_guaranteed function this way:

protocol Foo {
    func foo()
}
extension Foo {
    func foo() {}
}

The `foo()` function will now be an @in_guaranteed function taking `self`, correct? (any other ways to create an `@in_guaranteed` function easily?) This is probably me being a bit slow but what exactly do you mean with performing a store, passing the address to an @in_guaranteed function and then reloading the value? Very naively I thought about

class C: Foo {}
func something() {
    let c = C()
    var b: Foo = c   /* store */
    b.foo()          /* pass the address to an `@in_guaranteed` func */
    c.foo()          /* load again */
}

is this roughly what you had in mind?

Thanks,
  Johannes

[1]: https://bugs.swift.org/browse/SR-5403


More information about the swift-dev mailing list