[llvm-dev] [RFC] Should we add isa_or_null<>?

Hubert Tong via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 4 21:10:17 PDT 2019


On Thu, Apr 4, 2019 at 11:15 PM Aaron Ballman via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> On Thu, Apr 4, 2019 at 12:58 PM Chris Lattner <clattner at nondot.org> wrote:
> >
> >
> >
> > > On Apr 4, 2019, at 5:37 AM, Don Hinton via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
> > >
> > > I'd like to propose adding `isa_or_null<>` to replace the following
> usage pattern that's relatively common in conditionals:
> > >
> > >   var && isa<T>(var)  =>>  isa_or_null<T>(var)
> > >
> > > And in particular when `var` is a method call which might be
> expensive, e.g.:
> > >
> > >   X->foo() && isa<T>(X->foo())  =>>  isa_or_null<T>(X->foo())
> > >
> > > The implementation could be a simple wrapper around isa<>, and while
> the IR produced is only slightly more efficient, the elimination of an
> extra call could be worthwhile.
> >
> > I’d love to see this, I agree with downstream comments though that this
> name will be confusing.  isa_and_nonnull<>. ?
>
> tbh, I don't think the proposed name will be all that confusing --
> we're used to _or_null() returning "the right thing" when given null.
> isa_and_nonnull<> is a bit of a weird name for me, but I could
> probably live with it. We could spell it nonnull_and_isa<> to reflect
> the order of the operations, but that sort of hides the important part
> of the API (the "isa" bit).
>
I think "isa_nonnull" would read fine too. To me, the extra "and" makes the
ordering more of an issue.

-- HT


>
> ~Aaron
>
> >
> > -Chris
> >
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://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/20190405/fb1baab0/attachment.html>


More information about the llvm-dev mailing list