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

Chris Lattner via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 4 09:58:09 PDT 2019

> 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<>. ?


More information about the llvm-dev mailing list