[llvm-dev] RFC: Add guard intrinsics to LLVM

Chandler Carruth via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 22 23:18:04 PST 2016


I've not had time to really dig into all of this thread, but I wanted to
point out:

On Mon, Feb 22, 2016 at 10:27 PM Sanjoy Das via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Assuming everyone is on the same page, here's a rough high level agenda:
>
>
> # step A: Introduce an `interposable` function attribute
>
> We can bike shed on the name and the exact specification, but the
> general idea is that you cannot do IPA / IPO over callsites calling
> `interposable` functions without inlining them.  This attribute will
> (usually) have to be used on function bodies that can deoptimize (e.g. has
> a
> side exit / guard it in); but also has more general use cases.
>

Note that we already have this *exact* concept in the IR via linkage for
better or worse. I think it is really confusing as you are currently
describing it because it seems deeply overlapping with linkage, which is
where the whole interposition thing comes from, and yet you never mention
how it interacts with linkage at all. What does it mean to have a common
linkage function that lacks the interposable attribute? Or a LinkOnceODR
function that does have that attribute?

If the goal is to factor replaceability out of linkage, we should actually
factor it out rather than adding yet one more way to talk about this.

And generally, we need to be *really* careful adding function attributes.
Look at the challenges we had figuring out norecurse. Adding attributes
needs to be viewed as nearly as high cost as adding instructions,
substantially higher cost than intrinsics.


>
>
> # step B: Introduce a `side_exit` intrinsic
>
> Specify an `@llvm.experimental.side_exit` intrinsic, polymorphic on the
> return type:
>
>  - Consumes a "deopt" continuation, and replaces the current physical
>    stack frame with one or more interpreter frames (implementation
>    provided by the runtime).
>

I think it would be really helpful to work to describe these things in
terms of semantic contracts on the IR rather than in terms of
implementation strategies. For example, not all IR interacts with an
interpreter, and so I don't think we should use the term "interpreter" to
specify the semantic model exposed by the IR.

 - Calls to this intrinsic must be `musttail` (verifier will check this)
>  - We'll have some minor logic in the inliner such that when inlining @f
> into @g
>    in
>
>      define i32 @f() {
>        if (X) return side_exit() [ "deopt"(X) ];
>        return i32 20;
>      }
>
>      define i64 @g() {
>        if (Y) {
>          r = f() [ "deopt"(Y) ];
>          print(r);
>      }
>
>    We get
>
>      define i64 @g() {
>        if (Y) {
>          if (X) return side_exit() [ "deopt"(Y, X) ];
>          print(20);
>        }
>      }
>
>    and not
>
>      define i64 @g() {
>        if (Y) {
>          r = X ? (side_exit() [ "deopt"(Y, X) ]) : 20;
>          print(r);
>      }
>
>
> # step C: Introduce a `guard_on` intrinsic
>
> Will be based around what was discussed / is going to be discussed on
> this thread.
>
>
> (I think Philip was right in suggesting to split out a "step B" that
> only introduces a `side_exit` intrinsic.  We *will* have to specify
> them, since we'd like to optimize some after we've lowered guards into
> explicit control flow, and for that we need a specification of side
> exits.)
>
>
> # aside: non-managed languages and guards
>
> Chandler raised some points on IRC around making `guard_on` (and
> possibly `side_exit`?) more generally applicable to unmanaged
> languages; so we'd want to be careful to specify these in a way that
> allows for implementations in an unmanaged environments (by function
> cloning, for instance).
>
> -- Sanjoy
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160223/7e20468e/attachment.html>


More information about the llvm-dev mailing list